Hi i have an array which i am trying to copy then remove an element from. The issue is i think i am removing the element from the copy but it also removes the element from the original array. I have no idea what is going on. Im new to objective c so any help would be much appreciated.
NSArray *newarray = appDelegate.orginalArray;
[newarray removeObjectAtIndex: 2];
When i look at the arrays after removing the object it had removed it from both newarray and orginalArray why would this be?
Many thanks
This isn’t making a copy. Both
newArrayandappDelegate.originalArrayrefer to the same object. You would need to do this:Also note that I’m using
NSMutableArrayandmutableCopyto ensure the copy is mutable (i.e. supports adding and removing items)