• 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: Differences between -isEqual: and -isEqualTo:?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Differences between -isEqual: and -isEqualTo:?


  • Subject: Re: Differences between -isEqual: and -isEqualTo:?
  • From: Jim Correia <email@hidden>
  • Date: Thu, 18 Sep 2008 19:39:13 -0400

On Sep 18, 2008, at 7:32 PM, Shawn Erickson wrote:

On Thu, Sep 18, 2008 at 4:19 PM, Keith Duncan <email@hidden> wrote:
if two objects compare equal, then they must have the same hash [...]
[you] have to implement a corresponding -hash that maintains this invariant
rule.

Is there an example somewhere of what one should do to implement - hash to
reflect -isEqual:, I haven't done so in one of my classes and it works fine.
Would you just combine the -hash of the objects used to determine - isEqual:
in a logical manner, say XOR?

The only requirement is that if [objectA isEqual:objectB] returns true then [objectA hash] == [objectB hash] must be true as well.

Additional care must be taken if you are implementing a mutable object and intend to store it in a collection: the object's -hash cannot change while it is in the collection (so effectively, the object's hash cannot be derived from any mutable properties of the object.)


Jim
_______________________________________________

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: Differences between -isEqual: and -isEqualTo:?
      • From: Shawn Erickson <email@hidden>
    • Re: Differences between -isEqual: and -isEqualTo:?
      • From: Keith Duncan <email@hidden>
References: 
 >Differences between -isEqual: and -isEqualTo:? (From: Rick Mann <email@hidden>)
 >Re: Differences between -isEqual: and -isEqualTo:? (From: Dave DeLong <email@hidden>)
 >Re: Differences between -isEqual: and -isEqualTo:? (From: Charles Srstka <email@hidden>)
 >Re: Differences between -isEqual: and -isEqualTo:? (From: Ken Thomases <email@hidden>)
 >Re: Differences between -isEqual: and -isEqualTo:? (From: Keith Duncan <email@hidden>)
 >Re: Differences between -isEqual: and -isEqualTo:? (From: "Shawn Erickson" <email@hidden>)

  • Prev by Date: Re: Differences between -isEqual: and -isEqualTo:?
  • Next by Date: Re: Differences between -isEqual: and -isEqualTo:?
  • Previous by thread: Re: Differences between -isEqual: and -isEqualTo:?
  • Next by thread: Re: Differences between -isEqual: and -isEqualTo:?
  • Index(es):
    • Date
    • Thread