C primitive types
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 ...
Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.