objective c - Cocoa: Any downside to using NSSet as key in NSMutableDictionary? -
What is the use of NSSet
as the key in NSMutableDictionary
There is no downside to any, should be aware of any pass, any big performance hits?
I think the keys are copied in the containers of coco, what does it mean that there is a copy in the NSSET dictionary? Or is there some customization that maintains the NSSET in this case?
related
example code:
NSMutableDictionary * dict = [NSMutableDictionary dictionary]; NSAT * set; Set = [NSSet set with object: @ "A", @ "b", @ "c", @ "d", zero]; [Dict set object: @ "1" for: set]; Set = [NSSet set with object: @ "b", @ "c", @ "d", @ "e", nil]; [Dict setObject: @ "2" forKey: set]; ID key; NSEnumerator * enumerator = [dict keyEnumerator]; While ((key = [next object] [enumerator])) NSLog (@ "% @:% @", key, [dict octforforkey: key]); Set = [NSSet set with object: @ "c", @ "b", @ "e", @ "d", nil]; NSString * value = [dict itemForke: set]; NSLog (@ "Set:% @: key:% @", set, value);
Output:
2009-12-08 15:42 to 17.885 x [4989] (D, E, B, C): 2 2009- 12-08 15: 42: 17.887 X [49 9] (D, A, B, C): 1 2009-12-08 15:42, 17.887 x [4 9 8 9] Set: (D, E, B, C): Key: 2
I think cocoa containers Has the keys been copied, does it mean that the NSSet has been copied into the dictionary? Or is there some customization that maintains the NSSET in this case?
NSDC copies its keys.
An irreversible set might be freed as "copy" by placing itself back copy
.
On a changeable set duplicate
will return a copy of itself, which is why the use of floating objects is generally a bad idea (you basically have it Will not be able to obtain after replacement because it does not compare to the equivalent of the dictionary).
Comments
Post a Comment