Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3636618
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:03:21+00:00 2026-05-19T01:03:21+00:00

ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook); CFIndex nPeople = ABAddressBookGetPersonCount(addressBook); NSMutableArray *tempPeoples=[[NSMutableArray

  • 0
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);  
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

NSMutableArray *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=[tempPeoples copy];

This code gives exception b/c I want to convert NSMutableArray to NSArray
Please Help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:03:22+00:00Added an answer on May 19, 2026 at 1:03 am

    The subject reads, “How to convert NSArray to NSMutableArray“. To get an NSMutableArray from an NSArray, use the class method on NSMutableArray +arrayWithArray:.

    Your code does not show the declaration for peoples. Assuming it’s declared as an NSMutableArray, you can run into problems if you try to treat it as such. When you send the copy message to an NSMutableArray, you get an immutable object, NSArray, so if you try to add an object to a copied NSMutableArray, you will get an error.

    CFArrayRef is toll free bridged to NSArray, so you could simplify your code this way:

    CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
    //NSMutableArray *tempPeoples = [NSMutableArray arrayWithArray:(NSArray*)allPeople];
    // even better use the NSMutableCopying protocol on NSArray
    NSMutableArray *tempPeoples = [(NSArray*)allPeople mutableCopy];
    CFRelease(allPeople);
    return tempPeoples; // or whatever is appropriate to your code
    

    In the above code tempPeoples is an autoreleased NSMutableArray ready for you to add or remove objects as needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather unexpected result with the following code: ABAddressBookRef addressBook = ABAddressBookCreate();
I am trying to be an ABRecordRef that represents the contact info of a
I am creating a lookup table mapping contact phone numbers to their corresponding ABRecordRef
Do I need to release a Core Foundation objects to clear up memory? And
Apple provides the following sample code in their QuickContacts project for how to search
I want to store network carrier as a string (e.g. AT&T) for each contact
My question concerns markup that surrounds some of the default phone number labels in
I would like to list all phone numbers (or any other field) of people
The following code creates me an array of all my contacts in my address
I'm trying to set the contact image with the code below. I am not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.