Cover by Vandad Nahavandipoor

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

11.4. Retrieving Properties of Address Book Entries

Problem

You have retrieved a reference to an item in the address book, such as a person’s entry, and you want to retrieve that person’s properties, such as first and last names.

Solution

Use the ABRecordCopyValue function on the person’s Address Book record.

Discussion

The records in the address book database are of type ABRecordRef. Each record could be either a group or a person. We have not discussed groups yet, so let’s focus on people. Each person could have various types of information assigned to him, such as his first name, last name, email address, and so on. Bear in mind that many of these values are optional, and at the time of creating a new contact in the address book database, the user can simply leave out fields such as phone number, middle name, email address, URL, and so forth.

ABRecordCopyValue accepts an address book record and the property that has to be retrieved as its two parameters. The second parameter is the property of the record that we want to retrieve. Here are some of the common properties (all of these properties are defined as constant values in the ABPerson.h header file):

kABPersonFirstNameProperty

This value will retrieve the first name of the given person. The return value is of type CFStringRef, which can be cast to NSString with a bridge cast, so you can do just about anything you want with the results.

kABPersonLastNameProperty

This value will retrieve the last name of the given person. Like the first ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required