• 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: Comparing NSDictionary woes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing NSDictionary woes


  • Subject: Re: Comparing NSDictionary woes
  • From: Chris Hanson <email@hidden>
  • Date: Sun, 22 Jul 2007 15:25:35 -0700

On Jul 22, 2007, at 2:20 PM, Ken Tozier wrote:

Do your objects satisfy that test?


They should.

If they are custom subclasses of NSObject or some other class, and you haven't implemented -isEqual: yourself, chances are they *don't*.


When implementing "value" classes, you *must* explicitly implement - isEqual: and -hash on your objects in order for them to compare identical based on their contents. Otherwise, your class will fall back to -[NSObject isEqual:] which is a pointer-equality test and - [NSObject hash] which isn't based on the contents of the object.

Also, you should have unit tests for your classes so you can say for certain whether -isEqual: and -hash are behaving correctly. (The rule is that -hash must return the same value for objects that respond YES to -isEqual:, but objects that respond NO to -isEqual: don't necessarily need different hashes.)

  -- Chris

_______________________________________________

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: Comparing NSDictionary woes
      • From: Rosyna <email@hidden>
    • Re: Comparing NSDictionary woes
      • From: Ken Tozier <email@hidden>
References: 
 >Comparing NSDictionary woes (From: Ken Tozier <email@hidden>)
 >Re: Comparing NSDictionary woes (From: mmalc crawford <email@hidden>)
 >Re: Comparing NSDictionary woes (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: ASScriptMenuManager
  • Next by Date: Re: detecting mouse movement when window is inactive
  • Previous by thread: Re: Comparing NSDictionary woes
  • Next by thread: Re: Comparing NSDictionary woes
  • Index(es):
    • Date
    • Thread