Re: Using NSImages as keys to a dictionary
Re: Using NSImages as keys to a dictionary
- Subject: Re: Using NSImages as keys to a dictionary
- From: "Adam R. Maxwell" <email@hidden>
- Date: Sun, 14 May 2006 00:12:19 -0700
On May 13, 2006, at 14:16, Michael Ash wrote:
On 5/13/06, Adam R. Maxwell <email@hidden> wrote:
Another way to do this might be to create a CFMutableDictionary with
custom callbacks that retain keys instead of copying them, and
compares keys based on pointer equality; with toll-free bridging,
you'd just treat it as a standard NSMutableDictionary. You have to
ensure that the hash of the keys (NSImage instances) doesn't change
while they're in the dictionary, though.
Sadly, this doesn't work. While you can indeed treat such a
CFMutableDictionary as an NSMutableDictionary, the Cocoa methods will
not respect your custom callbacks. In other words, if you create a
CFMutableDictionary which does not copy its keys, then do [myCFDict
setObject:obj forKey:key], key *will* be copied.
Confirmed, and that sucks...we use custom dictionary/set/array
callbacks fairly often, so I'll have to check those. I think I
generally use CF functions to add values, so I'm probably safe.
Thanks for the warning.
For the OP's problem, I'd still use this instead of wrapping pointers
with NSValue and retaining them in a separate array, but YMMV.
I consider this a bug and have filed it as rdar://4350677 . The
obvious workaround is to use the actual CF functions instead, which is
not really a problem.
Using the CF functions is easy enough, but it wasn't evident to me
that this was required. Further, I'm fairly sure the custom equality
callback is used, at least in sets, so this seems inconsistent.
-- Adam
_______________________________________________
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