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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:06:46+00:00 2026-06-14T05:06:46+00:00

Copying an NSMutableArray using mutableCopy apparently creates a physical new copy of the array.

  • 0

Copying an NSMutableArray using mutableCopy apparently creates a physical new copy of the array. The evidence of this is that removal of an element from the copy using removeObjectAtIndex does not remove the element from the original. However if an element in the copy is changed, the element in the original is also changed. This is about as intuitive as a photon of light being both a particle and a wave and I do not understand it. Please can someone explain this to me.

Code follows.

NSMutableArray *dataArray = [NSMutableArray arrayWithObjects:
                                 [NSMutableString stringWithString:@"one"],
                                 [NSMutableString stringWithString:@"two"],
                                 [NSMutableString stringWithString:@"three"],
                                 [NSMutableString stringWithString:@"four"],
                                 nil];
    NSMutableArray *dataArray2;
    NSMutableString *mstr;
    dataArray2 = [dataArray mutableCopy];
    [dataArray2 removeObjectAtIndex:0];
    mstr    = [dataArray2 objectAtIndex:0];
    [mstr appendString:@"ONE"];
    NSLog(@"Data Array: ");
    for (NSString *elem in dataArray) {
        NSLog(@"%@",elem);
    }
    NSLog(@"Data Array2: ");
    for (NSString *elem in dataArray2) {
        NSLog(@"%@",elem);
    } 
  • 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-14T05:06:49+00:00Added an answer on June 14, 2026 at 5:06 am

    The mutableCopy method creates a shallow copy of the array, meaning that references to elements of the original array are copied to the new instance of NSMutableArray returned by mutableCopy. That is why manipulating (adding/removing elements) the copy of the array does not alter the composition of the original array, while changes to elements of the array that allow mutation become “visible” through both copies of the array.

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

Sidebar

Related Questions

I am copying a mutable array like this: //copy players' info into playerList from
Copying a File using a straight-forward approach in Python is typically like this: def
Copying an array would create a new instance of the array, but the objects
When copying large files using shutil.copy() , you get no indication of how the
when copying arrays using std::copy is there a way to check to see if
Possible Duplicate: Copying array by value in javascript How to copy an array of
I have an NSMutableArray that stores mousejoints for a Box2d physics simulation. When using
I am new to iPhone SKD.I want to know that if i am copying(i
I'm having trouble copying a row from one table to another using sqlite3 in
Possible Duplicate: deep copy NSMutableArray in Objective-C ? I have two arrays of length

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.