• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDictionary trouble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary trouble


  • Subject: Re: NSDictionary trouble
  • From: Kyle Sluder <email@hidden>
  • Date: Tue, 19 Jan 2010 15:18:19 -0800

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).

> 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

  • Follow-Ups:
    • Re: NSDictionary trouble
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >NSDictionary trouble (From: Shawn Rutledge <email@hidden>)
 >Re: NSDictionary trouble (From: Jeremy Pereira <email@hidden>)
 >Re: NSDictionary trouble (From: Shawn Rutledge <email@hidden>)

  • Prev by Date: Re: NSDictionary trouble
  • Next by Date: Re: NSDictionary trouble
  • Previous by thread: Re: NSDictionary trouble
  • Next by thread: Re: NSDictionary trouble
  • Index(es):
    • Date
    • Thread