-1

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:i1];

}// end of the for loop

// Peoples is NSArray
// peoples=[[NSArray alloc] initWithArray: tempPeoples];

peoples=[NSArray arrayWithArray:tempPeoples];

Please help

4
  • Same code, same problem but even less description than your earlier question: How to convert NSArray to NSMutableArray Commented Jan 5, 2011 at 13:38
  • Please explain on which line do you get the error, and what exactly is the error. Also @Abizem is correct - you've already posted a similar question, and the answers on that question are correct. Commented Jan 5, 2011 at 13:50
  • Ali. Not getting a solution is no reason to post the same question again. You were asked for further code/information in your original question; you should have answered those requests. Commented Jan 5, 2011 at 16:17
  • ok,sorry ,I found the solution thanks Commented Jan 6, 2011 at 4:49

1 Answer 1

4

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