CFMutableDictionary

Overview

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.

Topics

Creating a Mutable Dictionary

CFDictionaryCreateMutable

Creates a new mutable dictionary.

CFDictionaryCreateMutableCopy

Creates a new mutable dictionary with the key-value pairs from another dictionary.

Modifying a Dictionary

CFDictionaryAddValue

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

CFDictionaryRemoveAllValues

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

CFDictionaryRemoveValue

Removes a key-value pair.

CFDictionaryReplaceValue

Replaces a value corresponding to a given key.

CFDictionarySetValue

Sets the value corresponding to a given key.

Data Types

CFMutableDictionaryRef

A reference to a mutable dictionary object.

See Also

Opaque Types

CFFileDescriptor

The CFFileDescriptor provides an opaque type to monitor file descriptors for read and write activity via CFRunLoop.

CFStringTokenizer

CFStringTokenizer allows you to tokenize strings into words, sentences or paragraphs in a language-neutral way. It supports languages such as Japanese and Chinese that do not delimit words by spaces, as well as de-compounding German compounds. You can obtain Latin transcription for tokens. It also provides language identification API.