CFMutableDictionary manages dynamic dictionaries. The basic interface for managing dictionaries is provided by CFDictionary. CFMutableDictionary adds functions to modify the contents of a dictionary.

You create a mutable dictionary object using either the CFDictionaryCreateMutable(_:_:_:_:) or CFDictionaryCreateMutableCopy(_:_:_:) function. You can add key-value pairs using the CFDictionaryAddValue(_:_:_:) and CFDictionarySetValue(_:_:_:) functions. 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. You can remove key-value pairs using the CFDictionaryRemoveValue(_:_:) function. When removing key-value pairs from a dictionary, the keys and values are released.

CFMutableDictionary is “toll-free bridged” with its Cocoa Foundation counterpart, NSMutableDictionary. What this means is that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. This means that in a method where you see an NSMutableDictionary * parameter, you can pass in a CFMutableDictionaryRef, and in a function where you see a CFMutableDictionaryRef parameter, you can pass in an NSMutableDictionary instance. This also applies to concrete subclasses of NSMutableDictionary. See Toll-Free Bridged Types for more information on toll-free bridging.


Creating a Mutable Dictionary

Modifying a Dictionary

func CFDictionaryAddValue(CFMutableDictionary!, UnsafeRawPointer!, UnsafeRawPointer!)

Adds a key-value pair to a dictionary if the specified key is not already present.

func CFDictionaryRemoveAllValues(CFMutableDictionary!)

Removes all the key-value pairs from a dictionary, making it empty.

Data Types


A reference to a mutable dictionary object.