Re: NSDictionary trouble
Re: NSDictionary trouble
- Subject: Re: NSDictionary trouble
- From: Jean-Daniel Dupas <email@hidden>
- Date: Wed, 20 Jan 2010 00:25:25 +0100
Le 20 janv. 2010 à 00:18, Kyle Sluder a écrit :
> On Tue, Jan 19, 2010 at 3:09 PM, Shawn Rutledge
> <email@hidden> wrote:
>> Well yeah, that's one of the reasons java.lang.String is immutable.
>> But it helps that java.lang.Object has both hashCode and equals, so
>> any object can be put into a collection that depends on those... you
>> just have the option of improving the implementation of those for
>> better hash distribution, comparing two objects by content rather than
>> reference location, etc. I just wanted a hashtable that uses keys by
>> pointer rather than expecting to copy them. Nice to know that copying
>> protocol doesn't mean you have to actually copy it though.
>
> NSObject has -hash and -isEqual:. If you want a pointer-based
> dictionary, create a CFDictionary with the appropriate options, and
> cast it to NSDictionary* (read the documentation on Toll-Free Bridging
> to see why this is possible).
An other solution can be to use NSMapTable class. I prefer it to CFDictionary because the later is not really toll-free bridged when using custom key/value callbacks.
Even with a NULL or CFType Key callback, if you use NSMutableDictionary methods, is will try to copy the keys.
>> As for C++, you can use template containers to store either pointers
>> or copies of objects, whichever you like.
>
> STL containers are far more explicit about their internal behavior.
> It's possible to write a collection class that has the same
> restrictions as NSDictionary.
>
> --Kyle Sluder
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
>
-- Jean-Daniel
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden