Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > sorting in AddressBook API

sorting in AddressBook API
Thread Tools
F33
Fresh-Faced Recruit
Join Date: Dec 2002
Location: Los Angeles, CA
Status: Offline
Reply With Quote
Jan 30, 2003, 04:03 PM
 
Hi, I am trying to understand the AddressBook API and I can't figure out how to sort the results.

Suppose I have:

ABAddressBook *addressBook;
NSArray *everyone;

everyone holds all the people in my Address Book. How can I sort it, let's say, by LastName?

Dose the AddressBook API provides ways to sort? I can't seem to find it.

Any hint is greatly appreciated. Thank you.

- F33
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Jan 30, 2003, 04:11 PM
 
I recently came across the same thing.

The way I got round it was to add one method to ABPerson as a Category.

This method is a comparitor method that returns an NSComparisonResult.

you can then send the everyone array the sortedArrayUsingSelector: message

The code is below:

Code:
/* ABPersonAdditions.h */ // This category addition allows arrays of ABPeople to be sorted by Last Name. #import <AddressBook/AddressBook.h> @interface ABPerson (MyPersonAddition) -(NSComparisonResult)compareLastName:(ABPerson *)otherPerson; @end /* ABPersonAdditions.m */ #import "ABPersonAdditions.h" @implementation ABPerson (MyPersonAddition) -(NSComparisonResult)compareLastName:(ABPerson *)otherPerson { return ([[self valueForProperty: kABLastNameProperty] caseInsensitiveCompare: [otherPerson valueForProperty: kABLastNameProperty]]); } @end
     
F33  (op)
Fresh-Faced Recruit
Join Date: Dec 2002
Location: Los Angeles, CA
Status: Offline
Reply With Quote
Jan 30, 2003, 05:34 PM
 
Hi Diggory,

Thank you so much! That does the job. I will try to figure out how to sort by LastName, then FirstName now.

Again, thank you very much.

-f33
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:07 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2