On Tue, Jan 19, 2010 at 3:09 PM, Shawn Rutledge
<shawn.t.rutle...@gmail.com> 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).

> 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 (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

Reply via email to