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 8159257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:51:02+00:00 2026-06-06T17:51:02+00:00

Apparently mutableCopy copies by reference, not value. Ie if I do this: NSMutableArray arrayA

  • 0

Apparently mutableCopy copies by reference, not value. Ie if I do this:

NSMutableArray arrayA = [arrayB mutableCopy];

then change values of arrayB, then arrayA’s values will also be changed.

I think Java has a clone() method to copy by value.. is there an equivalent in objective c?

  • 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-06-06T17:51:03+00:00Added an answer on June 6, 2026 at 5:51 pm

    The mutableCopy method performs “shallow” copy. Each element of arrayA is a reference to an object that is also in arrayB. If you add elements to arrayA (or remove elements), arrayB will be unchanged, and vice versa. But since the elements of arrayA and arrayB reference the same objects, a change to one of those objects “shows up” in both arrays.

    If you want a one-level deep copy of arrayB, you can do this:

    NSMutableArray *arrayA = [[NSMutableArray alloc] initWithArray:arrayB copyItems:YES];
    

    That will have this effect:

    NSMutableArray *arrayA = [[NSMutableArray alloc] init];
    for (id element in arrayB) {
        [arrayA addObject:[element copy]]; //copies immutable objects to new array  
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently this Tomcat data source gets registered in JNDI. The crystal reports API will
Apparently this function in SDL_Mixer keeps dying, and I'm not sure why. Does anyone
Apparently this is a fairly often experienced issue. I'm not sure entirely where the
Apparently XmlNode.ChildNodes-list (in C# .Net) contains not only real child nodes, but also special
Apparently this used to work on ruby 1.8.7 but unfortunately not on 1.9.2 class
Apparently Microsoft.WindowsAzure.CloudConfigurationManager.GetSettings will start by looking in ServiceConfiguration.*.cscfg and then fall back to web.config
Apparently, there's been a big brouhaha over whether or not Python needs tail-call optimization
Apparently many people have run into this problem, but I have yet to be
Apparently I've done something I'm not aware of All my classes now have warnings
Apparently, I'm missing something fundamental. I'm having a problem with formatting the value of

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.