Reputation: 128
How can I sort my address book by first name. I'm using the ABContact class.
Upvotes: 0
Views: 916
Reputation: 11439
First you need to get an array of all the contacts with the method :
CFArrayRef ABAddressBookCopyArrayOfAllPeople (
ABAddressBookRef addressBook
);
Then you can create a mutable version of the array using :
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(
kCFAllocatorDefault,
CFArrayGetCount(people),
people
);
And you can sort this array with :
CFArraySortValues(
peopleMutable,
CFRangeMake(0, CFArrayGetCount(peopleMutable)),
(CFComparatorFunction) ABPersonComparePeopleByName,
(void*) ABPersonGetSortOrdering()
);
You have a fully documented sample in the Address Book Programming guide
Hope this helps, Vincent
Upvotes: 1