<!--
{
  "availability" : [
    "iOS: 2.0.0 - 11.0.0",
    "iPadOS: 2.0.0 - 11.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0",
    "tvOS: 9.0.0 - 11.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 4.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSArray/getObjects:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSArray(im)getObjects:"
  },
  "title" : "getObjects:"
}
-->

# getObjects:

Copies all the objects contained in the array to `aBuffer`.

```
- (void) getObjects:(ObjectType[]) objects;
```

## Parameters

`objects`

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

```objc
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

[`convenience init(objects: UnsafePointer<AnyObject>, count: Int)`](/documentation/Foundation/NSArray/init(objects:count:)-7dct1)

Creates and returns an array that includes a given number of objects from a given C array.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)