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

# setObject

Add or replace an object in the dictionary.

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

## Parameters

`aKey`

An object pointer used to lookup the object. The key should be uniqued within the dictionary. Usually an OSString is passed as the key.

`anObject`

Object to be added to the dictionary.

## Return Value

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

## 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.

---

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)