iPhone ABContact address book sorting.
How can I sort my address book by first n开发者_Go百科ame. I'm using the ABContact class.
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
精彩评论