Graphics Programs Reference
In-Depth Information
When an object is added to an array with the message
addObject:
, it is added at the
end of the array. You can also insert objects at a specific index - as long as that index is
less than or equal to the current number of objects in the array.
int numberOfObjects = [array count];
[array insertObject:object
atIndex:numberOfObjects];
Note that you cannot add
nil
to an array. If you need to add “holes” to an array, you must
use
NSNull
.
NSNull
is an object that represents
nil
and is used specifically for this
task.
[array addObject:[NSNull null]];
To retrieve the pointer to an object later, you send the message
objectAtIndex:
to the
array.
NSString *object = [array objectAtIndex:0];