<!--
{
  "availability" : [
    "DriverKit: -",
    "iOS: -",
    "iPadOS: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "DriverKit",
  "identifier" : "/documentation/DriverKit/OSArray/setObject-4ys3x",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "DriverKit"
    ],
    "preciseIdentifier" : "c:@S@OSArray@F@setObject#i#*1$@S@OSMetaClassBase#"
  },
  "title" : "setObject"
}
-->

# setObject

Sets an object as the member of the array at a given index.

```
bool setObject(uint32_t index, const OSMetaClassBase *anObject);
```

## Parameters

`index`

Zero based index less than or equal to the array count to add the object.

`anObject`

Object to be added to the array.

## Return Value

true on success, which retains the object, or false on failure which does not retain the object.

## Discussion

Sets an object as the member of the array at a given index. The array capacity will be grown if necessary.

---

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)