Hello all,
I have one mutableDictionary in which mutableArray and other object.
I copy this original dictionary in new dictionary using dictionaryWithditionary.
now when i reomve object from newdictionary then it not remove from originaldictionary.It working properly.
But it create problem for mutableArray. When i remove one object from mutalbleArray which is in newdictionary then it also remove from original dictionary.
Thank you.
Of course this happens... the arrays in both dictionaries are the same object. First off, the constructor you are using does not mention the word "copy", so it has no obligation to preform any copy as defined in NSCopying. However, even if it did use [NSDictionary copy], it would now be a deep copy. Deep copy includes copying all the child values for every object. Shallow copy (the default for [copy]) just copies pointers and primitive values.
Remember that you can't put an NSArray into a dictionary. You only put an NSArray* (pointer) into a dictionary. When you use [dictionaryWithDictionary:] or [initWithDictionary:], the new dictionary has copies of all of the values in the original array, including COPIES OF THE POINTERS. Both pointers still refer to the same array object, so operating on the array* in one of the dictionaries will will modify the "array" in both dictionaries.
Deep copying is a very delicate and frequently specific operation. It can be slow and can even cause recursive looping, so its never the default!
Check out
http://developer.apple.com/document...ions.html#//apple_ref/doc/uid/20001149-102844
Specifically, try using:
Code:
NSMutableDictionary* newDict = (NSMutableDictionary*) CFPropertyListCreateDeepCopy (
kCFAllocatorDefault,
yourDictonaryPointer,
kCFPropertyListMutableContainersAndLeaves
);
// you own new object
// do stuff
[newDict release];