Instance Method

compare:

Returns an NSComparisonResult value that indicates whether the number object’s value is greater than, equal to, or less than a given number.

Declaration

- (NSComparisonResult)compare:(NSNumber *)otherNumber;

Parameters

aNumber

The number to compare to the number object’s value.

This value must not be nil. If the value is nil, the behavior is undefined and may change in future versions of macOS.

Return Value

NSOrderedAscending if the value of aNumber is greater than the number object’s, NSOrderedSame if they’re equal, and NSOrderedDescending if the value of aNumber is less than the number object’s.

Discussion

The compare: method follows the standard C rules for type conversion. For example, if you compare an NSNumber object that has an integer value with an NSNumber object that has a floating point value, the integer value is converted to a floating-point value for comparison.

See Also

Comparing NSNumber Objects

- isEqualToNumber:

Returns a Boolean value that indicates whether the number object’s value and a given number are equal.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software