Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

21. Collection Classes > C primitive types

C primitive types

The collections covered in this chapter only hold objects. What if you want a collection of floats or ints or pointers to structures? You can wrap common C primitive types in an object. There are two classes that are designed specifically for this purpose. NSNumber holds C number types. NSValue can hold a pointer and some types of structs.

For instance, if you wanted to put the numbers 4 and 5.6 into an array, you would use NSNumber:

NSMutableArray *numList = [[NSMutableArray alloc] init];
[numList addObject:[NSNumber numberWithInt:4]];
[numList addObject:[NSNumber numberWithFloat:5.6]];

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint