Instance Method

getObjects:

Copies all the objects contained in the array to aBuffer.

Declaration

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

Parameters

aBuffer

A C array of objects of size at least the count of the array.

Discussion

The method copies into aBuffer all the objects in the array; the size of the buffer must therefore be at least the count of the array multiplied by the size of an object reference, as shown in the following example (note that this is just an example, you should typically not create a buffer simply to iterate over the contents of an array):

NSArray *mArray = // ...;
id *objects;
 
NSUInteger count = [mArray count];
objects = malloc(sizeof(id) * count);
 
[mArray getObjects:objects];
 
for (i = 0; i < count; i++) {
    NSLog(@"object at index %d: %@", i, objects[i]);
}
free(objects);

Special Considerations

This deprecated method is unsafe because it could potentially cause buffer overruns.

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:range:

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

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.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software