Re: Differences between -isEqual: and -isEqualTo:?
Re: Differences between -isEqual: and -isEqualTo:?
- Subject: Re: Differences between -isEqual: and -isEqualTo:?
- From: Jim Correia <email@hidden>
- Date: Thu, 18 Sep 2008 20:54:52 -0400
On Sep 18, 2008, at 8:36 PM, Shawn Erickson wrote:
On Sep 18, 2008, at 4:39 PM, Jim Correia wrote:
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.)
This isn't a requirement of isEqual: or hash and in fact doing such
a thing cannot break the requirement I stated and the obvious one I
didn't state... that an object that shouldn't be considered equal to
another needs to return false for [objectA isEqual:objectB] and
hashes may or may not be that same value.
The implied bit of text at the end of my parenthetical comment is "if
you expect to store the value in a hashtable, mutate, and later
retrieve it."
Expecting a set of mutable objects or a dictionary with mutable keys
to work correctly (note NSDictionary copies keys for this very
reason) under such situations in tenuous. It can be made to work if
you own the code for the mutable objects being used and want to add
such an assurance to your object's contract with out breaking the
expectation of isEqual:.
I wasn't thinking of the dictionary (key) case, but for the value case
in other hash-table like objects like NSSet.
Since mutable framework provided objects can (and do) change hash
values as they are mutated, I agree with your tenuous classification
of the situation. In the general case, storing mutable objects in hash-
table like collections outside of a well controlled and tightly scoped
scenario.
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