Re: How to clone a mutable dictionary
Re: How to clone a mutable dictionary
- Subject: Re: How to clone a mutable dictionary
- From: Jean-Daniel Dupas <email@hidden>
- Date: Fri, 24 Apr 2009 11:07:18 +0200
Le 24 avr. 09 à 10:50, Graham Cox a écrit :
On 24/04/2009, at 6:44 PM, Jean-Daniel Dupas wrote:
NSMutableDictionary *newThing2 = [newThing mutableCopy];
[newThing2 setObject:foo forKey:bar];
This doesn't copy the contents of the dictionary, it only makes a
mutable copy of the dictionary itself. If an object in the second
dictionary is mutated, the same object in the first dictionary
changes also. That is the OP's problem.
Of course, but that's not what this code is about:
newThing2 = [NSMutableDictionary dictionaryWithCapacity:20];
[newThing2 setDictionary:newThing];
[newThing2 setObject:foo forKey:bar]; // at this method line
[newThing objectForKey:bar] is now foo
Here, the OP tells that the original dictionary (newThing) is updated
when he set a value in the new dictionary (newThing2).
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden