11.6. Inserting a Group Entry into the Address Book

Problem

You want to categorize your contacts into groups.

Solution

Use the ABGroupCreate function.

Bear in mind that, as mentioned before, Core Foundation memory management is more complex than what Xcode’s static analyzer could process. Therefore, attempting to use the LLVM compiler to compile Core Foundation code with static analysis turned on might give you a lot of warnings. You can ignore these and test the code with Instruments to make sure your code does not leak, but I encourage you to familiarize yourself with memory management in Core Foundation by reading Apple’s “Memory Management Programming Guide for Core Foundation” document, as mentioned in the previous section.

Discussion

After retrieving the reference to the address book database, you can call the ABGroupCreate function to create a new group entry. However, you must perform a few more operations before you can insert this group into the address book operation. The first thing you have to do is set the name of this group using the ABRecordSetValue function with the kABGroupNameProperty property, as shown in the example code.

After the name of the group is set, add it to the address book database just like you add a new person’s entry—using the ABAddressBookAddRecord function. For more information about adding a new person’s entry to the address book database, please read Recipe 11.5.

Note

Inserting a new group with a name that already exists in the address book database ...

Get iOS 6 Programming Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.