---
title: replaceObject
framework: Kernel
role: symbol
role_heading: Instance Method
platforms: [driverkit 19.0+, macOS 10.15+]
path: kernel/osarray/3180821-replaceobject
---

# replaceObject

Removes a current member of the array and replaces it with another object.

## Declaration

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

```occ
virtual void replaceObject(unsigned int index, const OSMetaClassBase *anObject);
```

## Parameters

- `index`: Zero based index less than 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 added object and releases the current member, or false on failure which does not retain the object and leaves the current member.

## 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)
- [setObject](kernel/osarray/3433840-setobject.md)
- [iterateObjects](driverkit/osarray/iterateobjects.md)
- [removeObject](kernel/osarray/3180820-removeobject.md)
