beautypg.com

Apple WebObjects 3.5 User Manual

Page 199

background image

Commonly Used Array Methods

199

– insertObject:atIndex:

Inserts an object at a specified index. If the specified index is
already occupied, the objects at that index and beyond are shifted
down one slot to make room. The specified index can’t be greater
than the receiver’s count, and the specified object cannot be

nil

.

Array objects have a zero-based index. The first object in an array
is at index 0, the second is at index 1, and so on. You can insert only
new objects in ascending order—with no gaps. Once you add two
objects, the array’s size is 2, so you can insert objects at indexes 0,
1, or 2. Index 3 is illegal and out of bounds.

It is an error to specify

nil

as an argument to this method. You

cannot add

nil

to an array. It is also an error to specify an index that

is greater than the array’s count.

– removeObject:

Removes all objects in the array equivalent to a specified object,
and moves elements up as necessary to fill any gaps. Equivalency
is determined using the

isEqual:

method.

– removeObjectIdenticalTo:

Removes all occurrences of a specified object and moves elements
up as necessary to fill any gaps.

– removeObjectAtIndex:

Removes the object at a specified index and moves all elements
beyond the index up one slot to fill the gap. Arrays have a zero-
based index. The first object in an array is at index 0, the second is
at index 1, and so on.

It is an error to specify an index that is out of bounds (greater than
or equal to the array’s count).

– removeAllObjects

Empties the receiver of all of its elements.

– setArray:

Empties the receiver of all its elements, then adds the contents of
a specified array.