In This Chapter
Working with an array
Understanding Cocoa's Boolean type
Finding out what day it is
One of the main tasks that computers do well is manipulate data. Whether you need to calculate the national debt or keep track of the telephone numbers of the players in your poker club, computer programs can ease the task of handling information. Cocoa improves upon the various ways that you work with data in C.
This chapter takes you on a tour of some data types unique to Cocoa. The Foundation Framework defines these data types. You can continue to use the data types that you know from C, but after you see what Cocoa has to offer, you just might stop thinking about those old C types altogether.
When you program in Objective-C, you can use all the usual standard C numerical data types for making calculations. If you want to use these values with Cocoa's array objects, however, you're left out in the cold. For this reason, Cocoa offers you the
NSNumber class. One of its great uses is to wrap numbers in a Cocoa object, for use with other objects, such as
NSArray class is an array class that comes with the Foundation Kit. You hear more about it later in this chapter.
To create an
NSNumber object based on an integer value of 42, use code like this:
NSNumber *n = [NSNumber numberWithInt:42];
Here are methods for creating NSNumbers based on a variety of numerical types: