开发者

Error occurs when I convert NSMutableArray to NSArray

开发者 https://www.devze.com 2023-02-02 20:19 出处:网络
I want to convert NSMutableArray to NSArray to it gives error following is code ABAddressBookRef addressBook = ABAddressBookCreate();

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消