Re: Differences between -isEqual: and -isEqualTo:?
Re: Differences between -isEqual: and -isEqualTo:?
- Subject: Re: Differences between -isEqual: and -isEqualTo:?
- From: Ken Thomases <email@hidden>
- Date: Thu, 18 Sep 2008 17:19:27 -0500
On Sep 18, 2008, at 4:59 PM, Dave DeLong wrote:
On Sep 18, 2008, at 3:57 PM, Rick Mann wrote:
I see that NSObject (and its protocol) define -isEqual: and -
isEqualTo:. What's the difference? Why does something like
NSArray's -indexOfObject: use -isEqual: and not -isEqualTo:? So
that someone can redefine these for an existing class? Why does -
isEqualTo: even exist?
IIRC, isEqual: compares memory addresses, whereas isEqualTo:
compares hashes of the objects being compared. I also believe that
isEqual: is the preferred method.
Nope. isEqual: asks the object to compare itself to another. The
default implementation just uses identity (pointer comparison), but
many subclasses use value comparison or whatever is appropriate.
isEqualTo: is used for scripting support. By default, it's equivalent
to isEqual:, but a class can override it to perform different
scripting-specific comparison.
Cheers,
Ken
_______________________________________________
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