I want to convert NSMutableArray to NSArray to it gives error following is code
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
tempPeoples=[[NSMutableArray alloc]init];
for(int i=0;i<nPeople;i++){
ABRecordRef i1=CFArrayGetValueAtIndex(allPeople, i);
[tempPeoples addObject:i1];
//[peoples addObject:开发者_Go百科i1];
}// end of the for loop
// Peoples is NSArray
// peoples=[[NSArray alloc] initWithArray: tempPeoples];
peoples=[NSArray arrayWithArray:tempPeoples];
Please help
I found the solution using following code
ABAddressBookRef addressBook = ABAddressBookCreate();
NSArray *allPeople = (NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
tempPeoples= [NSMutableArray arrayWithCapacity:0];
for(int i=0;i<nPeople;i++){
ABRecordRef i1=CFArrayGetValueAtIndex(allPeople, i);
NSString* name = (NSString *)ABRecordCopyValue(i1,kABPersonFirstNameProperty);
[tempPeoples addObject:name];
// [peoples addObject:i1];
}// end of the for loop
peoples=[NSArray arrayWithArray:tempPeoples];
精彩评论