• 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
When do I need to override hash?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

When do I need to override hash?


  • Subject: When do I need to override hash?
  • From: Gideon King <email@hidden>
  • Date: Thu, 20 Aug 2009 09:28:35 +1000

I was just looking up the documentation to remind myself of the difference between isEqual: and isEqualTo: and saw that for your own custom objects to behave nicely in a collection, it apparently needs to override both isEqual: and hash.

But when I look at the specific documentation for things like NSArray and NSSet, it says that the actual comparison is done with a call to isEqual: (although it does mention that you should override hash too).

But when I look at the likes of the Cocoa Fundamentals Guide at http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html the example shows only overriding isEqual: (in the Object Comparison section).

So do I need to override hash too? If so, are there any recommendations as to how to determine the hash easily?

Thanks

Gideon
_______________________________________________

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: When do I need to override hash?
      • From: Nathan Vander Wilt <email@hidden>
    • Re: When do I need to override hash?
      • From: Nathan Vander Wilt <email@hidden>
    • Re: When do I need to override hash?
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: devil of a time with an NSImageView
  • Next by Date: Layer-backed view confused by bounds transformation
  • Previous by thread: Re: - [NSBitmapImageRep cacheDisplayInRect:toBitmapImageRep:] produces empty image
  • Next by thread: Re: When do I need to override hash?
  • Index(es):
    • Date
    • Thread