---
title: setObject
framework: driverkit
role: symbol
role_heading: Instance Method
path: driverkit/osdictionary/setobject-7q0u2
---

# setObject

Add or replace an object in the dictionary.

## Declaration

```occ
bool setObject(const char *aKey, const OSMetaClassBase *anObject);
```

## Parameters

- `aKey`: A c-string key. An OSString is created from aKey and used as the key for the dictionary.
- `anObject`: Object to be added to the dictionary.

## Return Value

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

## Discussion

Discussion The object is added to the dictionary with the key object. If an object with the given key existed prior to the call it is replaced and released. The dictionary capacity will be grown if necessary.

## See Also

### Accessing Keys and Values

- [getObject](driverkit/osdictionary/getobject-9ikoz.md)
- [getObject](driverkit/osdictionary/getobject-8k3ie.md)
- [setObject](driverkit/osdictionary/setobject-9b4z0.md)
- [removeObject](driverkit/osdictionary/removeobject-25qm5.md)
- [removeObject](driverkit/osdictionary/removeobject-156jh.md)
- [iterateObjects](driverkit/osdictionary/iterateobjects-9h89s.md)
- [iterateObjects](driverkit/osdictionary/iterateobjects-6cv0d.md)
- [OSDictionaryIterateObjectsBlock](driverkit/osdictionaryiterateobjectsblock.md)
- [OSDictionaryIterateObjectsCallback](driverkit/osdictionaryiterateobjectscallback.md)
