I am having an issue with two dictionaries. In my header file I declare a dictionary:
@property (strong, nonatomic) NSMutableDictionary *templateDictionary
The templateDictionary holds strings and dictionaries, such as 'blankCopy', which in turn holds other strings and dictionaries. I am also declaring a dictionary within my implementation file:
@property (strong, nonatomic) NSMutableDictionary *exampleDictionary
In my implementation I am trying to set part of the exampleDictionary to a portion of the templateDictionary like so:
[self.exampleDictionary setObject:[templateDictionary objectForKey:@"blankCopy"] forKey:@"template"];
This works until I change anything within exampleDictionary's 'template'. Now when I go back to the templateDictionary it has also changed. I figured this was because it was pointing back. I have tried the following but all don't have any effect:
[self.exampleDictionary setObject:[[templateDictionary objectForKey:@"blankCopy"] copy] forKey:@"template"];
[self.exampleDictionary setObject:[[templateDictionary objectForKey:@"blankCopy"] mutableCopy] forKey:@"template"];
[self.exampleDictionary setObject:[NSMutableDictionary dictionaryWithDictionary:[templateDictionary objectForKey:@"blankCopy"]] forKey:@"template"];
Any ideas as to what's wrong and how to fix it, or how to copy a dictionary object by values?