0 Replies - 22642 Views - Last Post: 17 January 2013 - 03:26 AM

#1 ambuj  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-September 10

get contatcs firstname in nsmutable array

Posted 17 January 2013 - 03:26 AM

I'm making an app in which i want to access the contact's first name and store them in to nsmutable array so that i can get the values of that array like array[0] up to array[i-1] and print them in table view.Here is my code:
CFErrorRef error = NULL;

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &error);

if (addressBook != nil)
{
    contacts_Image_List=[[NSMutableArray alloc]init];
    NSLog(@"Succesful.");

    NSArray *allContacts = (__bridge_transfer NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);




    NSUInteger i = 0;
    for (i = 0; i < [allContacts count]; i++)
    {
Person *person = [[Person alloc] init];



        ABRecordRef contactPerson = (__bridge ABRecordRef)allContacts[i];

        NSString *firstName = (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonFirstNameProperty);
        NSString *lastName =  (__bridge_transfer NSString *)ABRecordCopyValue(contactPerson, kABPersonLastNameProperty);
        NSString *fullName = [NSString stringWithFormat:@"%@ %@", firstName, lastName];

        person.firstName = firstName;
        person.lastName = lastName;
        person.fullName = fullName;

       // person.userThumb[i]=firstName;

       //[person.userThumb[i] addObject:@"firstName"];

       //above line gives null

        NSLog(@"%@",person.userThumb[i]);


my mutable array is in .h class.

This post has been edited by macosxnerd101: 17 January 2013 - 01:59 PM
Reason for edit:: Please use code tags


Is This A Good Question/Topic? 0
  • +

Page 1 of 1