I have a weird problem. I have a singleton with dictionary in it. This dictionary is updated regularly in runtime. In a viewcontroller I access this singleton dictionary and create a new NSMutableArray.
@property (nonatomic, retain) NSMutableArray *myArray;
_myArray = [[NSMutableArray alloc] init];
_myArray = [NSMutableArray arrayWithArray:[[[DataCenter singleton] myDict] allValues]];
It's not a weird problem, it's how Objective-C works. Your singleton array is just a collection of object references. You've filled
_myArray with those exact same references. All modifications in one will be reflected by the other because, well, they're the same objects.
In order to actually make new objects, you need to make a copy. Something like this:
_myArray = [[NSMutableArray alloc] initWithArray:[[[DataCenter singleton] myDict] allValues] copyItems:YES];
I can't test with
[[[DataCenter singleton] myDict] allValues] in my compiler, but a contrived example incase you want to experiment with deepCopy and array.
NSArray *array = [NSArray arrayWithObject:@"foo"]; NSMutableArray* _myArray = [[NSMutableArray alloc] initWithArray:array copyItems:YES];