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.

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.

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

    NSNumber* stringProperty = [NSNumber numberWithInteger:kABStringProperty];
    NSString* testProperty = @"com.example.myProperty";
    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);