Instance Method

getObjects:range:

Copies the objects contained in the array that fall within the specified range to aBuffer.

Declaration

- (void)getObjects:(ObjectType  _Nonnull *)objects range:(NSRange)range;

Parameters

aBuffer

A C array of objects of size at least the length of the range specified by aRange.

aRange

A range within the bounds of the array.

If the location plus the length of the range is greater than the count of the array, this method raises an NSRangeException.

Discussion

The method copies into aBuffer the objects in the array in the range specified by aRange; the size of the buffer must therefore be at least the length of the range multiplied by the size of an object reference, as shown in the following example (this is solely for illustration—you should typically not create a buffer simply to iterate over the contents of an array):

NSArray *mArray = // an array with at least six elements...;
id *objects;
 
NSRange range = NSMakeRange(2, 4);
objects = malloc(sizeof(id) * range.length);
 
[mArray getObjects:objects range:range];
 
for (i = 0; i < range.length; i++) {
    NSLog(@"objects: %@", objects[i]);
}
free(objects);

See Also

Querying an Array

- containsObject:

Returns a Boolean value that indicates whether a given object is present in the array.

count

The number of objects in the array.

- getObjects:

Copies all the objects contained in the array to aBuffer.

Deprecated
firstObject

The first object in the array.

lastObject

The last object in the array.

- objectAtIndex:

Returns the object located at the specified index.

- objectAtIndexedSubscript:

Returns the object at the specified index.

- objectsAtIndexes:

Returns an array containing the objects in the array at the indexes specified by a given index set.

- objectEnumerator

Returns an enumerator object that lets you access each object in the array.

- reverseObjectEnumerator

Returns an enumerator object that lets you access each object in the array, in reverse order.