Q:

Getting all group names in Contacts

How can I get all group names that is saved inside the contacts?  Below is my code for your reference: 
NSMutableArray *list = [NSMutableArray array];
ABAddressBookRef myAddressBook = ABAddressBookCreate();
CFArrayRef allSources = ABAddressBookCopyArrayOfAllGroups(myAddressBook);

list = [NSMutableArray arrayWithArray: (__bridge NSArray*) allSources];

NSLog(@"GROUPS %@",[list objectAtIndex:0]);

The NSLog returns a  but I need to get the group name itself. 
Thanks. 

A:

Use the ABRecordCopyCompositeName() function. 
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
if (addressBook ! = NULL) {
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        if (granted) {
            CFArrayRef allGroups = ABAddressBookCopyArrayOfAllGroups(addressBook);
            if (allGroups ! = NULL) {
                NSMutableArray *names = [NSMutableArray array];
                for (int i = 0; i < CFArrayGetCount(allGroups); i++) {
                    ABRecordRef group = CFArrayGetValueAtIndex(allGroups, i);
                    CFStringRef name = ABRecordCopyCompositeName(group);
                    [names addObject:(__bridge NSString *)name];
                    CFRelease(name);
                }
                NSLog(@"names = %@", names);
                CFRelease(allGroups);
            }
        }
        CFRelease(addressBook);
    });
}

