0

I am facing an issue with the values in NSMutablearray. I have two NSMutablearray, both are holding the same content using mutablecopy. The issue is that when I modify a value in one array, the corresponding value in the second array also get modified. How to resolove this. Please help me.

1
  • show your code please Commented Sep 3, 2013 at 9:25

1 Answer 1

1

mutableCopy copies by reference, not value. So, any change to one of those objects affects for both arrays.

You could realize different methods to overcome this situation.

// first method

nameArray2 = [NSMutableArray new];
[nameArray2 addObjectsFromArray:nameArray1];

// second method

nameArray2 = [[NSMutableArray alloc] initWithArray:nameArray1 copyItems:YES];

Best regards.

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.