In cases where you just want to check if two NSNumber properties have the same value, from the Apple documentation it seems like using
- (BOOL)isEqualToNumber:(NSNumber *)aNumber
is the easiest and most efficient way to compare two NSNumber values.
For example:
if ([someNumber isEqualToNumber:someOtherNumber]) {
The documentation also says: "This method is more efficient than comparison: if you know that two objects are numbers."
Whenever you need to know less or more value, they offer
- (NSComparisonResult)compare:(NSNumber *)aNumber
but personally, I would prefer at this point to just pull out the integer values (or double values) and use regular <and> for comparison, because it makes the code much easier to read, for example:
if (firstNumber.intValue > secondNumber.intValue) {
Something like this is much easier to read than calls to -compare :, in my opinion.
Eric
Erik van der Neut Jan 23 '14 at 2:12 2014-01-23 02:12
source share