Advertisement
Guest User

Untitled

a guest
Mar 30th, 2011
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. //
  2. //  AdressBookModel.m
  3. //  Smsflatrate
  4. //
  5. //  Created by Artjom Zabelin on 3/24/11.
  6. //  Copyright 2011 ArtworkAD. All rights reserved.
  7. //
  8. #import "AddressBookModel.h"
  9. #import <AddressBookUI/AddressBookUI.h>
  10.  
  11. #define RELEASE_SAFELY(__POINTER){[__POINTER release]; __POINTER = nil;}
  12. #define RELEASE_SAFELY_CF(X)  { CFRelease(X); X = NULL; }
  13.  
  14. @implementation AddressBookModel
  15.  
  16. @synthesize searchResults = _searchResults;
  17.  
  18.  
  19. - (id)init {
  20.     if ((self = [super init])) {
  21.         _delegates = nil;
  22.         _searchResults = nil;
  23.     }
  24.     return self;
  25. }
  26.  
  27. - (void)dealloc {
  28.     RELEASE_SAFELY(_delegates);
  29.     RELEASE_SAFELY(_searchResults);
  30.     [super dealloc];
  31. }
  32.  
  33. ///////////////////////////////////////////////////////////////////////////////////////////////////
  34. // TTModel
  35.  
  36. - (NSMutableArray*)delegates {
  37.     if (!_delegates) {
  38.         _delegates = TTCreateNonRetainingArray();
  39.     }
  40.     return _delegates;
  41. }
  42.  
  43. - (BOOL)isLoadingMore {
  44.     return NO;
  45. }
  46.  
  47. - (BOOL)isOutdated {
  48.     return NO;
  49. }
  50.  
  51. - (BOOL)isLoaded {
  52.     return YES;
  53. }
  54.  
  55. - (BOOL)isLoading {
  56.     return NO;
  57. }
  58.  
  59. - (BOOL)isEmpty {
  60.     return !_searchResults.count;
  61. }
  62.  
  63. - (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
  64. }
  65.  
  66. - (void)invalidate:(BOOL)erase {
  67. }
  68.  
  69. - (void)cancel {
  70.     //issue
  71.    [_delegates perform:@selector(modelDidCancelLoad:) withObject:self];
  72.     //exception from my comment here
  73.     //[_delegates makeObjectsPerformSelector:@selector(modelDidCancelLoad:) withObject:self];
  74. }
  75.  
  76.  
  77. - (void)search:(NSString*)text {
  78.     [self cancel];
  79.    
  80.     if (text.length) {
  81.         //issue
  82.         [_delegates perform:@selector(modelDidStartLoad:) withObject:self];
  83.        
  84.         ABAddressBookRef addressBook = ABAddressBookCreate();
  85.        
  86.         CFStringRef searchText = CFStringCreateWithCString(NULL, [text cStringUsingEncoding:NSUTF8StringEncoding], kCFStringEncodingUTF8);
  87.         self.searchResults = (NSArray*) ABAddressBookCopyPeopleWithName(addressBook, searchText);
  88.        
  89.         RELEASE_SAFELY_CF(searchText);
  90.         //issue
  91.         [_delegates perform:@selector(modelDidFinishLoad:) withObject:self];
  92.        
  93.         RELEASE_SAFELY_CF(addressBook);
  94.     } else {
  95.         self.searchResults = nil;
  96.     }
  97.     //issue
  98.     [_delegates perform:@selector(modelDidChange:) withObject:self];
  99. }
  100.  
  101. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement