0

I'm developing an iPhone app for a small business owner.
All of the biz owner's clients are in the iPhone's Contacts (AddressBook)

The model will include a "Client" class which will be selected from the biz owner's list of contacts in the AddressBook. Seems like the Client class should have just a reference (pointer) to the uniqueID from the AddressBook.

From this post it seems like subclassing ABRecord is not an option.

I'm thinking that [client lastName] should return the string from the address book.

Here's my implementation of Client class' getters:

Client.m
- (NSString *)firstName
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, [self   employeeId]);
    return (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
}
- (NSString *)lastName
{
    ABAddressBookRef addressBook = ABAddressBookCreate();
    ABRecordRef foo = ABAddressBookGetPersonWithRecordID(addressBook, [self employeeId]);
    return (NSString *)ABRecordCopyValue(foo, kABPersonLastNameProperty);
}

Is there a better way to do this?

Another way to pose the question: In iOS, is there a nice technique for creating a thin wrapper around AddressBook records?

I played around with Groups in AddressBook but felt like the framework's support was not quite there.

Community
  • 1
  • 1
Norbert Ryan
  • 51
  • 1
  • 4
  • Only way I see to improve that code is to put that ABRecordRef person into an instance variable so you don't call those 2 lines of code all the time, just once in init. – Filip Radelic Aug 05 '11 at 22:11
  • And about keeping just the unique id of the contact; keep in mind this id can change if user backs up the device and restores it to another one, or if they turn on/off mobileme/exchange sync for contacts so it's best to keep the first and last name (which people rarely change) too so you can react if that happens. – Filip Radelic Aug 05 '11 at 22:15
  • thanks! will heed the advice on the first/last name – Norbert Ryan Aug 05 '11 at 22:29

0 Answers0