The following code creates me an array of all my contacts in my address book by first name and last name. The problem is, I have one contact that keeps showing up with an empty first name and last name. I can't find that contact in my actual address book. Can anyone suggest how to debug this to figure out the source of the mystery ghost contact?
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *peopleArray = (NSMutableArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSMutableArray *allNames = [NSMutableArray array];
for (id person in peopleArray) {
NSMutableString *firstName = [(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) autorelease];
NSMutableString *lastName = [(NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) autorelease];
ABMutableMultiValueRef multiValueEmail = ABRecordCopyValue(person, kABPersonEmailProperty);
if (ABMultiValueGetCount(multiValueEmail) > 0) {
NSString *email = [(NSString *)ABMultiValueCopyValueAtIndex(multiValueEmail, 0) autorelease];
}
if (![firstName length]) {
firstName = @"";
}
if (![lastName length]) lastName = @"";
[allNames addObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName]];
}
The person type is of type NSCFType. I could easily do something like:
if (![lastName length] && ![firstName length]) continue;
.. and be done with the problem. I'm curious though what entry in my AddressBook is coming up as a ghost. I've tried introspecting the object with gdb, but can't get anything valuable out of it.
I'd like to see all properties for person, but derefing the object to (ABPerson*) doesn't appear to do it.
I've also tried using CFShow(person) that reveals it to be type CPRecord. Can't find further documentation on that, however.
Is there something in gdb I can do to further inspect this particular person object to see where the source of it is coming from?