Datasheet

776
Interfacing with the Address Book Application
Listing 1-19: Adopting the Protocol
@interface AddHotelController :
UIViewController <UITextFieldDelegate,
ABPeoplePickerNavigationControllerDelegate> {
There are four basic objects you need to understand in order to interact
with the Address Book database:
Address Books
Records
Single-value properties
Multi-value properties
Address Books let you interact with the Address Book database and
save changes to it. To use an Address Book, declare an instance of
ABAddressBookRef and set it to the value returned from the function
ABAddressBookCreate.
You won’t declare an instance of ABAddressBookRef to access the Address
Book in this section, but you will when you add a contact in the next section.
In the Address Book database, information is stored in records. Each
record (ABRecordRef) represents a person or group. The function
ABRecordGetRecordType returns kABPersonType if the record is a
person, and kABGroupType if it’s a group. Here, you’ll be working only with
persons.
Within a record, the data is stored as a collection of properties (similar to the
Objective-C properties you’re used to). The properties available for group
and person objects are different, but the functions used to access them are
the same. The functions ABRecordCopyValue and ABRecordSetValue get
and set properties, respectively. Properties can also be removed completely,
using the function ABRecordRemoveValue.
Person records are made up of both single-value and multi-value properties.
I’ll explain properties in great detail in a moment.
Start by adding the code in Listing 1-20 — the key delegate method as far as
you are concerned — to AddHotelController.m. That’s because when
the user selects a person from the Address Book, this is the message that’s
sent to your delegate.
41_542934-bk07ch01.indd 77641_542934-bk07ch01.indd 776 3/23/10 11:01 PM3/23/10 11:01 PM