I am trying to add and subsequently read objects in an array
I have created this IOS code to load data from my address book into an array. When I try to read the data back and display it, the only displayed data is that of that of the last address added (and many copies of it). I'm pretty sure the problem is an easy fix, but I can't see why this doesn't work:
CFArrayRef _allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );
NSMutableArray *masters = [[NSMutableArrayalloc] init];
PVMaster *person = [[PVMasteralloc] init];
for ( int i = 0; i < nPeople; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(_allPeople, i );
person._firstName = (__bridge_transferNSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty);
person._lastName = (__bridge_transferNSString*)ABRecordCopyValue(ref,kABPersonLastNameProperty);
[masters addObject: person];
NSLog(@"person %d %@ %@ [%@]\n",i,person._firstName,person._lastName);
}
for ( int i = 0; (i < [masters count]-1); i++ ){
person = [masters objectAtIndex:i];
NSLog(@"person %d %@ %@ \n",i,person._firstName,person._lastName);
}
I would appreciate suggestions on how to get this code to work.
Mac mini, iOS 8.1.3