-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

Abizern
  • 146,289
  • 39
  • 203
  • 257
Ali
  • 10,774
  • 10
  • 56
  • 83
  • Same code, same problem but even less description than your earlier question: [How to convert NSArray to NSMutableArray](http://stackoverflow.com/questions/4569478/how-to-convert-nsarray-to-nsmutablearray) – Abizern Jan 05 '11 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. – Moszi Jan 05 '11 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. – Abizern Jan 05 '11 at 16:17
  • ok,sorry ,I found the solution thanks – Ali Jan 06 '11 at 04:49

1 Answers1

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];
Ali
  • 10,774
  • 10
  • 56
  • 83