Le 24 avr. 09 à 10:35, Steve Cronin a écrit :

Folks;

Its been a long day and maybe I'm just in need of sleep but I'm bamboozeled...

I have an NSMutableDictionary (newThing) that is set up based on some user defaults and current contextual data.
newThing is fine.

What I want to do is clone newThing (newThing2) and leave the values in newThing alone.
(I'll want to come and get newThing3 sooner or later)

Everything I do causes any change I make in newThing2 to also be made in newThing.

newThing2 = [NSMutableDictionary dictionaryWithCapacity:20];
[newThing2 setDictionary:newThing];
[newThing2 setObject:foo forKey:bar]; // at this method line [newThing objectForKey:bar] is now foo

I've tried [newThing copy) and enumerating over [newThing allKeys] doing a [newThing2 setObject:forKey]...
All with the same result....

How do I make an independent clone of newThing1?   (XC3  / 10.5.6)

I'm sorry if this is something silly!
Steve

NSMutableDictionary *newThing2 = [newThing mutableCopy];
[newThing2 setObject:foo forKey:bar];


But review you test, your first code sample should works too. How do you check the newThing changed too ?


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to