<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFDictionary",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFDictionaryRef"
  },
  "title" : "CFDictionary"
}
-->

# CFDictionary

```
class CFDictionary
```

## Overview

CFDictionary and its derived mutable type, [`CFMutableDictionary`](/documentation/CoreFoundation/CFMutableDictionary), manage associations of key-value pairs. CFDictionary creates static dictionaries where you set the key-value pairs when first creating a dictionary and cannot modify them afterward; CFMutableDictionary creates dynamic dictionaries where you can add or delete key-value pairs at any time, and the dictionary automatically allocates memory as needed.

A key-value pair within a dictionary is called an entry. Each entry consists of one object that represents the key and a second object that is that key’s value. Within a dictionary, the keys are unique. That is, no two keys in a single dictionary are equal (as determined by the equal callback). Internally, a dictionary uses a hash table to organize its storage and to provide rapid access to a value given the corresponding key.

Keys for a CFDictionary may be of any C type, however note that if you want to convert a CFPropertyList to XML, any dictionary’s keys must be CFString objects.

You create static dictionaries using either the [`CFDictionaryCreate(_:_:_:_:_:_:)`](/documentation/CoreFoundation/CFDictionaryCreate(_:_:_:_:_:_:)) or [`CFDictionaryCreateCopy(_:_:)`](/documentation/CoreFoundation/CFDictionaryCreateCopy(_:_:)) function. Key-value pairs are passed as parameters to [`CFDictionaryCreate(_:_:_:_:_:_:)`](/documentation/CoreFoundation/CFDictionaryCreate(_:_:_:_:_:_:)). When adding key-value pairs to a dictionary, the keys and values are not copied—they are retained so they are not invalidated before the dictionary is deallocated.

CFDictionary provides functions for querying the values of a dictionary. The function [`CFDictionaryGetCount(_:)`](/documentation/CoreFoundation/CFDictionaryGetCount(_:)) returns the number of key-value pairs in a dictionary; the [`CFDictionaryContainsValue(_:_:)`](/documentation/CoreFoundation/CFDictionaryContainsValue(_:_:)) function checks if a value is in a dictionary; and [`CFDictionaryGetKeysAndValues(_:_:_:)`](/documentation/CoreFoundation/CFDictionaryGetKeysAndValues(_:_:_:)) returns a C array containing all the values and a C array containing all the keys in a dictionary.

The [`CFDictionaryApplyFunction(_:_:_:)`](/documentation/CoreFoundation/CFDictionaryApplyFunction(_:_:_:)) function lets you apply a function to all key-value pairs in a dictionary.

CFDictionary is “toll-free bridged” with its Cocoa Foundation counterpart, <doc://com.apple.documentation/documentation/Foundation/NSDictionary>. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an `NSDictionary *` parameter, you can pass in a `CFDictionaryRef`, and in a function where you see a `CFDictionaryRef` parameter, you can pass in an NSDictionary instance. This also applies to concrete subclasses of NSDictionary. See [Toll-Free Bridged Types](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677) for more information on toll-free bridging.

## Topics

### Creating a dictionary

[`CFDictionaryCreate(_:_:_:_:_:_:)`](/documentation/CoreFoundation/CFDictionaryCreate(_:_:_:_:_:_:))

Creates an immutable dictionary containing the specified key-value pairs.

[`CFDictionaryCreateCopy(_:_:)`](/documentation/CoreFoundation/CFDictionaryCreateCopy(_:_:))

Creates and returns a new immutable dictionary with the key-value pairs of another dictionary.

### Examining a dictionary

[`CFDictionaryContainsKey(_:_:)`](/documentation/CoreFoundation/CFDictionaryContainsKey(_:_:))

Returns a Boolean value that indicates whether a given key is in a dictionary.

[`CFDictionaryContainsValue(_:_:)`](/documentation/CoreFoundation/CFDictionaryContainsValue(_:_:))

Returns a Boolean value that indicates whether a given value is in a dictionary.

[`CFDictionaryGetCount(_:)`](/documentation/CoreFoundation/CFDictionaryGetCount(_:))

Returns the number of key-value pairs in a dictionary.

[`CFDictionaryGetCountOfKey(_:_:)`](/documentation/CoreFoundation/CFDictionaryGetCountOfKey(_:_:))

Returns the number of times a key occurs in a dictionary.

[`CFDictionaryGetCountOfValue(_:_:)`](/documentation/CoreFoundation/CFDictionaryGetCountOfValue(_:_:))

Counts the number of times a given value occurs in the dictionary.

[`CFDictionaryGetKeysAndValues(_:_:_:)`](/documentation/CoreFoundation/CFDictionaryGetKeysAndValues(_:_:_:))

Fills two buffers with the keys and values from a dictionary.

[`CFDictionaryGetValue(_:_:)`](/documentation/CoreFoundation/CFDictionaryGetValue(_:_:))

Returns the value associated with a given key.

[`CFDictionaryGetValueIfPresent(_:_:_:)`](/documentation/CoreFoundation/CFDictionaryGetValueIfPresent(_:_:_:))

Returns a Boolean value that indicates whether a given value for a given key is in a dictionary, and returns that value indirectly if it exists.

### Applying a function to a dictionary

[`CFDictionaryApplyFunction(_:_:_:)`](/documentation/CoreFoundation/CFDictionaryApplyFunction(_:_:_:))

Calls a function once for each key-value pair in a dictionary.

### Getting the CFDictionary type ID

[`CFDictionaryGetTypeID()`](/documentation/CoreFoundation/CFDictionaryGetTypeID())

Returns the type identifier for the CFDictionary opaque type.

### Callbacks

[`CFDictionaryApplierFunction`](/documentation/CoreFoundation/CFDictionaryApplierFunction)

Prototype of a callback function that may be applied to every key-value pair in a dictionary.

[`CFDictionaryCopyDescriptionCallBack`](/documentation/CoreFoundation/CFDictionaryCopyDescriptionCallBack)

Prototype of a callback function used to get a description of a value or key in a dictionary.

[`CFDictionaryEqualCallBack`](/documentation/CoreFoundation/CFDictionaryEqualCallBack)

Prototype of a callback function used to determine if two values or keys in a dictionary are equal.

[`CFDictionaryHashCallBack`](/documentation/CoreFoundation/CFDictionaryHashCallBack)

Prototype of a callback function invoked to compute a hash code for a key. Hash codes are used when key-value pairs are accessed, added, or removed from a collection.

[`CFDictionaryReleaseCallBack`](/documentation/CoreFoundation/CFDictionaryReleaseCallBack)

Prototype of a callback function used to release a key-value pair before it’s removed from a dictionary.

[`CFDictionaryRetainCallBack`](/documentation/CoreFoundation/CFDictionaryRetainCallBack)

Prototype of a callback function used to retain a value or key being added to a dictionary.

### Data Types

[`CFDictionaryKeyCallBacks`](/documentation/CoreFoundation/CFDictionaryKeyCallBacks)

This structure contains the callbacks used to retain, release, describe, and compare the keys in a dictionary.

[`CFDictionaryValueCallBacks`](/documentation/CoreFoundation/CFDictionaryValueCallBacks)

This structure contains the callbacks used to retain, release, describe, and compare the values in a dictionary.

### Constants

[Predefined Callback Structures](/documentation/CoreFoundation/cfdictionary-predefined-callback-structures)

CFDictionary provides some predefined callbacks for your convenience.

## See Also

  [Property List Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFPropertyLists/CFPropertyLists.html#//apple_ref/doc/uid/10000130i)

  [Collections Programming Topics for Core Foundation](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFCollections/CFCollections.html#//apple_ref/doc/uid/10000124i)



---

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)