Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between isEqualTo: and isEqual:

What on earth is the difference between these methods?

like image 282
lbrndnr Avatar asked Aug 17 '11 17:08

lbrndnr


2 Answers

isEqual: is part of the NSObject protocol and is meant for comparing objects.

isEqualTo: is part of the Cocoa AppleScript support infrastructure (specifically, NSComparisonMethods, which allow AppleScript to compare Cocoa objects). It's normally the same as isEqual:, but can be overridden if you want equality to work differently internally and in a script.

like image 67
Chuck Avatar answered Nov 14 '22 13:11

Chuck


isEqualTo: is part of the NSComparisonMethods informal protocol, which also contains methods like isGreaterThan: and isNotEqualTo:, and is used for scripting support. And:

The default implementation for this method provided by NSObject returns YES if an isEqualTo: message sent to the same object would return YES.

So when sending this message to an NSObject (or any subclass which does not override it) you will get the same behavior as isEqual:, however, you should be using isEqual: instead.

like image 31
jtbandes Avatar answered Nov 14 '22 13:11

jtbandes