On 19 Jan 2010, at 23:06, Jens Alfke wrote: > > On Jan 19, 2010, at 10:46 AM, Kirk Kerekes wrote: > >> NSDictionary will use almost any object as a key: >> >> From the docs: >> "In general, a key can be any object (provided that it conforms to the >> NSCopying protocol...)" >> >> -- and if it is an immutable object, that -copy is just a -retain. > > Yes, but he said he wants to use a view as the key. Views are not immutable, > and do copy themselves in response to -copy. Having a dictionary whose key > objects are copies of your live views is not very useful. (Especially since > the copied view will have a different hashcode from the original one, so you > can't even look it up using the original view anymore...)
Well he could write a category to give him an object that satisfies all the criteria e.g (written in Mail). @interface NSView(DictionaryKey) -(NSNumber*) dictionaryKey; @end @implementation NSView(DictionaryKey) -(NSNumber*) dictionaryKey { return [NSNumber numberWithUnsignedLongLong: (unsigned long long) self]; } @end Then he could do things like: [myDictionary setObject: foo forKey: [myView dictionaryKey]]; ... bar = [myDictionary objectForKey [myView dictionaryKey]]; The above creates a key based on the address of the NSView. > > —Jens_______________________________________________ > > 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/adc%40jeremyp.net > > This email sent to a...@jeremyp.net ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ _______________________________________________ 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