Graphics Programs Reference
In-Depth Information
So, to recap, in your command line tool, you created an instance of NSMutableArray
and added four instances of NSString to it, as shown in Figure 2.7 .
Figure 2.7 NSMutableArray instance
Arrays can only hold references to Objective-C objects. This means primitives and C
structures cannot be added to an array. For example, you cannot have an array of int s.
Also, because arrays hold pointers to objects, a single array can contain objects of differ-
ent types . This is different from most strongly-typed languages where an array can only
hold objects of its declared type.
You can ask an array how many objects it is currently storing by sending it the message
count .
int numberOfObjects = [array count];
This information is important because if you ask for an object from an array at an index
that is greater than the number of objects in the array, an exception will be thrown. (Ex-
ceptions are very bad; they will most likely cause your application to crash. We'll talk
more about exceptions at the end of this chapter.)
 
Search WWH ::




Custom Search