From Apple documentation:
Returns a Boolean value that indicates whether the receiver and a given object are equal. (required) This method defines what it means for instances to be equal. For example, a container object might define two containers as equal if their corresponding objects all respond YES to an isEqual: request. See the NSData, NSDictionary, NSArray, and NSString class specifications for examples of the use of this method. If two objects are equal, they must have the same hash value. This last point is particularly important if you define isEqual: in a subclass and intend to put instances of that subclass into a collection. Make sure you also define hash in your subclass.
if you do like this
if([obj1 isEqual:obj2])
and obj1
, or obj2
is nil
then you will get NO
. (if this is what you meant by your question)
- Now
if(obj1 == obj2)
This is a pointer comparison. Pointers