An object representing a dynamic collection of key-value pairs, for use instead of a Dictionary
variable in cases that require reference semantics.
SDKs
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
class NSMutableDictionary : NSDictionary
Overview
The NSMutable
class declares the programmatic interface to objects that manage mutable associations of keys and values. It adds modification operations to the basic operations it inherits from NSDictionary
.
NSMutable
is “toll-free bridged” with its Core Foundation counterpart, CFMutable
. See Toll-Free Bridging for more information on toll-free bridging.
Setting Values Using Subscripting
In addition to the provided instance methods, such as set
, you can access NSDictionary
values by their keys using subscripting.
let value = "someValue"
mutableDictionary["someKey"] = value
Subclassing Notes
There should typically be little need to subclass NSMutable
. If you do need to customize behavior, it is often better to consider composition rather than subclassing.
Methods to Override
In a subclass, you must override both of its primitive methods:
You must also override the primitive methods of the NSDictionary
class.