I have an NSMutableArray that I'm passing into a tableViewController. The user will access and update data in the array. Add objects and remove objects.
To be able to get back to the state of the array before the user interacted with it, I thought I would make a copy of the array. That way if the user decided to cancel and not go ahead, I could just pass the copyArray back into the original array.
However, when I update some data on the original array, it get updated on the copy array as well.
And no, I didn't assign them to each other. I used the following code.
array2 = [array1 copy];
I have even tried the longwinded one.
NSMutableArray *newArray = [[NSMutableArray alloc] initWithArray:oldArray copyItems:YES];
But if I set copyItems to YES, the app crashes with this error.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SaleItem copyWithZone:]: unrecognized selector sent to instance 0xa21f3b0'