November 2013
Beginner
325 pages
9h 47m
English
The collections covered in this chapter only hold objects. What if you want a collection of floats or ints? You can wrap common C number types using NSNumber.
You can create a literal NSNumber instance using the @ symbol – similar to how you create literal NSString instances.
For instance, if you wanted to put the numbers 4 and 5.6 into an
array, you would create the instance of NSNumber and then add the NSNumber object to the array:
NSMutableArray *list = [[NSMutableArray alloc] init]; [list addObject:@4]; [list addObject:@5.6];
Note that you cannot do math directly with an NSNumber, only with primitives. You must first extract the primitive value using one of several NSNumber methods, do the math, and then ...
Read now
Unlock full access