Both methods return equal results. Of course, -[NSObject isEqual:]
doesn't compare the pointers of objects, it somehow check the inner fields or whatever. So what's the point of using exactly -[NSNumber isEqualToNumber:]
to compare two NSNumber
s?
From the docs:
Two NSNumber objects are considered equal if they have the same id values or if they have equivalent values (as determined by the compare: method). This method is more efficient than compare: if you know the two objects are numbers.
So it handles id equals and number comparison.
They are essentially identical, although isEqual has to do a type check on the class of the object passed in. isEqualToNumber does type checking at compile-time, which is better when possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With