Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

get contatcs firstname in nsmutable array

$
0
0
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.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>