Changes

Jump to: navigation, search

Understanding Objective-C Number Objects

2 bytes added, 15:48, 20 November 2009
no edit summary
In [[Objective-C 2.0 Data Types]] we looked at the basic data types supported by Objective-C including a range of types for working with numbers. These data types are what is are known as ''primitive types'' in that they simply allow values to be stored in memory and are not objects.
In order to work with numbers in object form, Objective-C provides the ''NSNumber'' class. This class is one of the stranger additions to the Objective-C language in that functionally speaking, number objects don't give you anything that you can't already do with primitive number types. It seems the sole purpose of the NSNumber class is to allow numbers to be stored in an NSArray object, which only handles objects.
</pre>
The ''compare'' method is used when you need to know whether one number is less than, greater than or equal to another when those numbers are held in number objects.The method returns the result of the comparison in the form of an NSComparisonResult enumeration. Possible settings are ''NSOrderedSame'' if the numbers are equal, ''NSOrderedAscending'' is the value stored in the first object is less than the number stored in the second and ''NSOrderedDescending'' if the opposite is true:
<pre>

Navigation menu