---
title: setObject
framework: Kernel
role: symbol
role_heading: Instance Method
platforms: [driverkit 19.0+, macOS 10.15.2+]
path: kernel/osarray/3433840-setobject
---

# setObject

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

## Declaration

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

```occ
virtual bool setObject(unsigned int 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](kernel/osarray/3180816-getobject.md)
- [getLastObject](kernel/osarray/3180814-getlastobject.md)
- [getNextIndexOfObject](kernel/osarray/3180815-getnextindexofobject.md)
- [setObject](kernel/osarray/3180822-setobject.md)
- [iterateObjects](driverkit/osarray/iterateobjects.md)
- [replaceObject](kernel/osarray/3180821-replaceobject.md)
- [removeObject](kernel/osarray/3180820-removeobject.md)
