// populate 'project' with contents of key in `gDictRoot`
NSDictionary *project = [gDictRoot valueForKeyPath:@"root.project0"];
// modify 'project' as necessary - actual code omitted for brevity
[project setValue:[someDict valueForKey:@"foo"] forKeyPath:@"parameters.foo"];
// add 'project' to 'gDictRoot' so it isn't lost when the view is dismissed
[gDictRoot setValue:project forKeyPath:@"root.project2"];
Third line, where I add project to gDictRoot – project0 also gets modified. Don’t know why.
The behavior that you see is due to the fact that both
project0andproject2point to the same dictionary instance. The change to one of them will always reflect in the other one.If you do not want this behavior, make a copy of
project0before making itproject2: