Reputation: 9930
I'm trying to get just the first 100 of contacts from the Address Book. What I've done is getting all the contacts and then tried to get only the first 100. For some reason that doesn't work (code below).
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allContacts = ABAddressBookCopyArrayOfAllPeople(addressBook);
NSRange theRange;
theRange.location = 0;
theRange.length = 100;
CFArrayRef allContactsNew = (CFArrayRef)[(NSMutableArray *)allContacts subarrayWithRange:theRange];//This gets an error
Would appreciate help here. Also, If you know any other method to get only the first 100 or so directly from the Address Book that could be very helpful.
Upvotes: 0
Views: 210
Reputation: 10738
It worked correctly when I made these changes:
theRange.length = MIN(100, CFArrayGetCount(allContacts)); //avoid array out of bounds errors
CFArrayRef allContactsNew = CFBridgingRetain([(NSArray *)CFBridgingRelease(allContacts) subarrayWithRange:theRange]); //Add CFBridging functions recommended by Xcode
Upvotes: 1