Re: Objects as keys NSMutableDictionary
Re: Objects as keys NSMutableDictionary
- Subject: Re: Objects as keys NSMutableDictionary
- From: Rosyna <email@hidden>
- Date: Sun, 9 Jul 2006 22:16:50 -0700
No biggy...
NSMutableDictionary*
happyDict=[(NSMutableDictionary*)CFDictionaryCrateMutable(NULL, 0,
&kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)
autorelease];
Now you can treat happyDict like any other NSMutableDicitonary and
put anything as the keys. Toll free bridging at work.
the default implementation of -hash just returns the pointer value,
IIRC, so it's fine to use mutable objects as keys since their pointer
value does not change in relation to their content.
Ack, at 7/10/06, email@hidden said:
"Methods that add entries to dictionaries-whether as part of
initialization (for all dictionaries) or during modification (for
mutable dictionaries)- don't add each value object to the dictionary
directly, but copy each key argument and add the copy to the
dictionary. In Objective-C, the dictionary copies each key argument
(keys must conform to the NSCopying protocol) and adds the copies to
the dictionary. Each corresponding value object receives a retain
message to ensure that it won't be deallocated before the dictionary
is through with it."
--
Sincerely,
Rosyna Keller
Technical Support/Holy Knight/Always needs a hug
Unsanity: Unsane Tools for Insanely Great People
It's either this, or imagining Phil Schiller in a thong.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden