I have a NSMutableArray is my delegate that I am using in one of my view controllers as well.
So in viewDidLoad I make a mutable copy of my NSMutableArray like this
You should do a deepCopy, i use this one and works perfectly, made by Sherm Pendley †.
I assume you did not implemented the mutableCopyWithZone: correctly.
You need to implement the NSMutableCopying protocol for the objects you put in the array, this way you could pass a new instance of that object for that case.
- (id)mutableCopyWithZone:(NSZone *)zone
{
YourCustomModel *aCopy = [[[self class] allocWithZone:zone] init];
if (aCopy) {
// set properties
}
return aCopy
}
That's because the mutable copy of the array is referencing the same objects as mydelegate.array is referencing, so if you change one object property, it's changed in both arrays, as it's the same object.
You could implement NSCopying protocol in your objects and you can then call initWithArray:copyItems: NSArray method.
Hope that helps.
Try this.
allitems =[NSMutableArray arrayWithArray:mydelegate.array];