---
title: setObject
framework: driverkit
role: symbol
role_heading: Instance Method
path: driverkit/osarray/setobject-4ys3x
---

# setObject

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

## Declaration

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

Return Value True on success, which retains the object, or false on failure which does not retain the object.

## Discussion

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

## See Also

### Accessing Elements

- [getObject](driverkit/osarray/getobject.md)
- [getLastObject](driverkit/osarray/getlastobject.md)
- [getNextIndexOfObject](driverkit/osarray/getnextindexofobject.md)
- [setObject](driverkit/osarray/setobject-3bore.md)
- [iterateObjects](driverkit/osarray/iterateobjects.md)
- [replaceObject](driverkit/osarray/replaceobject.md)
- [removeObject](driverkit/osarray/removeobject.md)
- [OSArrayAppendValue](driverkit/osarrayappendvalue.md)
- [OSArrayReplaceValue](driverkit/osarrayreplacevalue.md)
