<!--
{
  "availability" : [
    "DriverKit: -",
    "iOS: -",
    "iPadOS: -",
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "DriverKit",
  "identifier" : "/documentation/DriverKit/OSDictionary",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "DriverKit"
    ],
    "preciseIdentifier" : "c:@S@OSDictionary"
  },
  "title" : "OSDictionary"
}
-->

# OSDictionary

A container for a collection with elements that are key-value pairs.

```
class OSDictionary;
```

## Overview

OSDictionary is a collection class for objects derived from OSObject. Storage and access are associative, based on keys that are uniqued OSObjects. OSString is commonly used as a key since it is uniqued. When adding an object to an OSDictionary, you provide a string identifier, which can then used to retrieve that object or remove it from the dictionary. Setting an object with a key that already has an associated object replaces the original object.

You must generally cast retrieved objects from OSObject to the desired class using the OSDynamicCast macro. This macro returns the object cast to the desired class, or `NULL` if the object isn’t derived from that class.

As with all DriverKit collection classes, OSDictionary retains objects added to it, and releases objects removed from it (or replaced). An OSDictionary also grows as necessary to accommodate new objects.

OSArray provides no concurrency protection; it’s up to the usage context to provide any protection necessary.

## Topics

### Creating a Dictionary

[`static OSDictionaryPtr withCapacity(uint32_t capacity);`](/documentation/DriverKit/OSDictionary/withCapacity)

Allocates an OSDictionary object with preallocated capacity.

[`static OSDictionaryPtr withDictionary(const OSDictionary *dictionary, uint32_t capacity);`](/documentation/DriverKit/OSDictionary/withDictionary)

Allocates an OSDictionary object with given members and preallocated capacity.

[`static OSDictionaryPtr withObjects(const OSObject **values, const OSObject **keys, uint32_t count, uint32_t capacity);`](/documentation/DriverKit/OSDictionary/withObjects)

Allocates an OSDictionary object with given members and preallocated capacity.

[`OSDictionaryPtrOSDictionaryCreate();`](/documentation/DriverKit/OSDictionaryCreate)

[`bool merge(const OSDictionary *otherDictionary);`](/documentation/DriverKit/OSDictionary/merge)

Adds all members of a dictionary to this dictionary.

[`virtual void free();`](/documentation/DriverKit/OSDictionary/free)

[`virtual void flushCollection();`](/documentation/DriverKit/OSDictionary/flushCollection)

Removes and drops references to all members of dictionary.

### Accessing Keys and Values

[`OSObject * getObject(const OSObject *aKey) const;`](/documentation/DriverKit/OSDictionary/getObject-9ikoz)

Returns a member of the dictionary.

[`OSObject * getObject(const char *aKey) const;`](/documentation/DriverKit/OSDictionary/getObject-8k3ie)

Returns a member of the dictionary.

[`bool setObject(const OSObject *aKey, const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSDictionary/setObject-9b4z0)

Add or replace an object in the dictionary.

[`bool setObject(const char *aKey, const OSMetaClassBase *anObject);`](/documentation/DriverKit/OSDictionary/setObject-7q0u2)

Add or replace an object in the dictionary.

[`void removeObject(const OSObject *aKey);`](/documentation/DriverKit/OSDictionary/removeObject-25qm5)

Remove an object by key from the dictionary.

[`void removeObject(const char *aKey);`](/documentation/DriverKit/OSDictionary/removeObject-156jh)

Remove an object by key from the dictionary.

[`bool iterateObjects(OSDictionaryIterateObjectsBlock block) const;`](/documentation/DriverKit/OSDictionary/iterateObjects-9h89s)

Iterates the dictionary calling a callback block for each member.

[`virtual bool iterateObjects(OSCollectionIterateObjectsBlock block) const;`](/documentation/DriverKit/OSDictionary/iterateObjects-6cv0d)

Iterates the dictionary calling a callback block for each member.

[`typedef _Bool (^)(class OSObject *, class OSObject *) OSDictionaryIterateObjectsBlock;`](/documentation/DriverKit/OSDictionaryIterateObjectsBlock)

[`typedef _Bool (*)(void *, class OSObject *, class OSObject *) OSDictionaryIterateObjectsCallback;`](/documentation/DriverKit/OSDictionaryIterateObjectsCallback)

### Getting and Setting Values

[`OSObjectPtrOSDictionaryGetValue(OSDictionaryPtr obj, const char *key);`](/documentation/DriverKit/OSDictionaryGetValue)

[`const char *OSDictionaryGetStringValue(OSDictionaryPtr obj, const char *key);`](/documentation/DriverKit/OSDictionaryGetStringValue)

[`uint64_t OSDictionaryGetUInt64Value(OSDictionaryPtr obj, const char *key);`](/documentation/DriverKit/OSDictionaryGetUInt64Value)

[`bool OSDictionarySetValue(OSDictionaryPtr obj, const char *key, OSObjectPtr value);`](/documentation/DriverKit/OSDictionarySetValue)

[`void OSDictionarySetStringValue(OSDictionaryPtr obj, const char *key, const char *value);`](/documentation/DriverKit/OSDictionarySetStringValue)

[`void OSDictionarySetUInt64Value(OSDictionaryPtr obj, const char *key, uint64_t value);`](/documentation/DriverKit/OSDictionarySetUInt64Value)

[`typedef OSDictionary * OSDictionaryPtr;`](/documentation/DriverKit/OSDictionaryPtr)

### Inspecting a Dictionary

[`virtual uint32_t ensureCapacity(uint32_t newCapacity);`](/documentation/DriverKit/OSDictionary/ensureCapacity)

Allocates capacity for members in dictionary.

[`virtual uint32_t getCapacity() const;`](/documentation/DriverKit/OSDictionary/getCapacity)

Returns count of currently allocated capacity for members in dictionary.

[`virtual uint32_t getCount() const;`](/documentation/DriverKit/OSDictionary/getCount)

Returns count of members in dictionary.

[`uint32_t OSDictionaryGetCount(OSDictionaryPtr obj);`](/documentation/DriverKit/OSDictionaryGetCount)

### Modifying the Dictionary Items

[`bool OSDictionaryApply(OSDictionaryPtr obj, OSDictionaryApplier applier);`](/documentation/DriverKit/OSDictionaryApply)

[`typedef _Bool (^)(const char *, class OSObject *) OSDictionaryApplier;`](/documentation/DriverKit/OSDictionaryApplier)

### Comparing Dictionaries

[`bool isEqualTo(const OSDictionary *aDictionary) const;`](/documentation/DriverKit/OSDictionary/isEqualTo-3c1k0)

Compares all members of two dictionaries with isEqualTo().

[`bool isEqualTo(const OSDictionary *aDictionary, const OSCollection *keys) const;`](/documentation/DriverKit/OSDictionary/isEqualTo-2p9or)

Compares certain members of two dictionaries with isEqualTo().

[`virtual bool isEqualTo(const OSMetaClassBase *anObject) const;`](/documentation/DriverKit/OSDictionary/isEqualTo-3kuk7)

Compares the dictionary with an OSObject

## Relationships

### Inherits From

[`OSCollection`](/documentation/DriverKit/OSCollection)

---

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)