2

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 Person.h class.

1 Answer 1

1

On each iteration just do:

[person.yourMutableArray addObject:fullName]

Just ensure that your MutableArray has already been allocated, and that you only allocate it once.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.