views:

30

answers:

1

This is my code:

    ABAddressBookRef _addressBookRef = ABAddressBookCreate ();
    NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);
    NSMutableArray* _allItems = [[NSMutableArray alloc] initWithCapacity:[allPeople count]]; // capacity is only a rough guess, but better than nothing
  for (id record in allPeople) {
        CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty);
        NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
        CFRelease(phoneProperty);
        for (NSString *phone in phones) {
            NSString* compositeName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
            NSString* field = [[NSString] stringWithFormat@"%@:%@",compositeName,phone];            
            [compositeName release];
            [_allItems addObject:field];
            for ( NSString *txt in _allItems )
            {
                contacts.text = [contacts.text stringByAppendingFormat:@"%@\n",txt];
            }
        }
        [phones release];
    }


    CFRelease(_addressBookRef);
    [allPeople release];
    allPeople = nil;

}

i basically want to dump the entire addressbook into a UItextView called contacts.text and have just the name and number like this NAME:NUMBER seperated by the :. i am currently getting a error on the line

 NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];

any help would be awesome :D

Thanks Mason

A: 

NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];

should be

NSString* field = [NSString stringWithFormat:@"%@:%@",compositeName,phone];