I have this code:
secondArray = [firstArray objectAtIndex:1];
The object at index 1 is already an NSMutableArray inside [firstArray]. The problem is that when I change secondArray, the firstArray also changes.
How can I stop this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
The best way to keep it from changing is to copy the array instead of set it. I had that problem before, and this is what did the trick for me
EDIT: just so I don’t give you poor information, I’m going to change this to a more generalized version:
This should better fit your situation. I have tested it twice to be sure by creating arrays and cloning them, then modifying the clones to see they are the only objects being modified