Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // AdressBookModel.m
- // Smsflatrate
- //
- // Created by Artjom Zabelin on 3/24/11.
- // Copyright 2011 ArtworkAD. All rights reserved.
- //
- #import "AddressBookModel.h"
- #import <AddressBookUI/AddressBookUI.h>
- #define RELEASE_SAFELY(__POINTER){[__POINTER release]; __POINTER = nil;}
- #define RELEASE_SAFELY_CF(X) { CFRelease(X); X = NULL; }
- @implementation AddressBookModel
- @synthesize searchResults = _searchResults;
- - (id)init {
- if ((self = [super init])) {
- _delegates = nil;
- _searchResults = nil;
- }
- return self;
- }
- - (void)dealloc {
- RELEASE_SAFELY(_delegates);
- RELEASE_SAFELY(_searchResults);
- [super dealloc];
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- // TTModel
- - (NSMutableArray*)delegates {
- if (!_delegates) {
- _delegates = TTCreateNonRetainingArray();
- }
- return _delegates;
- }
- - (BOOL)isLoadingMore {
- return NO;
- }
- - (BOOL)isOutdated {
- return NO;
- }
- - (BOOL)isLoaded {
- return YES;
- }
- - (BOOL)isLoading {
- return NO;
- }
- - (BOOL)isEmpty {
- return !_searchResults.count;
- }
- - (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
- }
- - (void)invalidate:(BOOL)erase {
- }
- - (void)cancel {
- //issue
- [_delegates perform:@selector(modelDidCancelLoad:) withObject:self];
- //exception from my comment here
- //[_delegates makeObjectsPerformSelector:@selector(modelDidCancelLoad:) withObject:self];
- }
- - (void)search:(NSString*)text {
- [self cancel];
- if (text.length) {
- //issue
- [_delegates perform:@selector(modelDidStartLoad:) withObject:self];
- ABAddressBookRef addressBook = ABAddressBookCreate();
- CFStringRef searchText = CFStringCreateWithCString(NULL, [text cStringUsingEncoding:NSUTF8StringEncoding], kCFStringEncodingUTF8);
- self.searchResults = (NSArray*) ABAddressBookCopyPeopleWithName(addressBook, searchText);
- RELEASE_SAFELY_CF(searchText);
- //issue
- [_delegates perform:@selector(modelDidFinishLoad:) withObject:self];
- RELEASE_SAFELY_CF(addressBook);
- } else {
- self.searchResults = nil;
- }
- //issue
- [_delegates perform:@selector(modelDidChange:) withObject:self];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement