Mac OS X Reference Library Apple Developer
Search

Adding Properties to Address Book Records

You can add your own properties to the people and groups in the address book. For example, if you’re creating a small application to manage a dog club, you could add properties to each person that specify the name and breed of that person’s dog. Or if you’re creating an application to manage business contacts, you could add a property that lists all the meetings and phone calls a user has had with that person. These properties are stored in the Address Book database. Applications that don’t know about the new properties aren’t affected by them and don’t modify them.

Note: Data stored in custom properties are not synced across MobileMe. If your application depends on this data being synced on multiple computers, it needs to sync the data itself. See Sync Services Programming Guide for more details on syncing.

Do not sync any of the data stored in the default properties. The Address Book framework already syncs this data, and attempting to sync it from your application may lead to data loss.

When deciding whether to add a property to the Address Book record, keep these issues in mind:

To add properties to every person or group, use the ABPerson or ABGroup class method addPropertiesAndTypes:. These procedures take a dictionary, in which the keys are the names of the new properties and the values are their types. Note that the property names must be unique. You may want to use reverse-DNS style names for your properties, to make sure no one else uses the same name; for example, org.dogclub.dogname or com.mycompany.buildingNumber. The type can be one of the types or a multivalue list of one of the types listed in “Property Types” in Address Book Objective-C Constants Reference.

The following code listing adds a custom property, and then removes it:

    NSNumber* stringProperty = [NSNumber numberWithInteger:kABStringProperty];
    NSString* testProperty = @"com.apple.devpubs.testProperty";
    NSDictionary* dict = [NSDictionary dictionaryWithObject:stringProperty
                                                     forKey:testProperty];
 
    NSInteger result = [ABPerson addPropertiesAndTypes:dict];
    NSLog(@"Added %d properties.", result);
 
    result = [ABPerson removeProperties:[NSArray arrayWithObject:testProperty]];
    NSLog(@"Removed %d properties.", result);



Last updated: 2010-08-03

Did this document help you? Yes It's good, but... Not helpful...