---
title: NSMutableDictionary
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsmutabledictionary
---

# NSMutableDictionary

A dynamic collection of objects associated with unique keys.

## Declaration

```swift
class NSMutableDictionary
```

## Overview

Overview In Swift, you can use this type instead of a Dictionary variable in cases that require reference semantics. The NSMutableDictionary 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. NSMutableDictionary is “toll-free bridged” with its Core Foundation counterpart, CFMutableDictionary. See Toll-Free Bridging for more information on toll-free bridging. Setting Values Using Subscripting In addition to the provided instance methods, such as setObject(_:forKey:), you can access NSDictionary values by their keys using subscripting. Subclassing Notes There should typically be little need to subclass NSMutableDictionary. 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: setObject(_:forKey:) removeObject(forKey:) You must also override the primitive methods of the NSDictionary class.

## Topics

### Creating and Initializing a Mutable Dictionary

- [init(capacity:)](foundation/nsmutabledictionary/init(capacity:).md)
- [init()](foundation/nsmutabledictionary/init().md)
- [init(sharedKeySet:)](foundation/nsmutabledictionary/init(sharedkeyset:).md)

### Adding Entries to a Mutable Dictionary

- [setObject(_:forKey:)](foundation/nsmutabledictionary/setobject(_:forkey:).md)
- [setValue(_:forKey:)](foundation/nsmutabledictionary/setvalue(_:forkey:).md)
- [addEntries(from:)](foundation/nsmutabledictionary/addentries(from:).md)
- [setDictionary(_:)](foundation/nsmutabledictionary/setdictionary(_:).md)

### Removing Entries From a Mutable Dictionary

- [removeObject(forKey:)](foundation/nsmutabledictionary/removeobject(forkey:).md)
- [removeAllObjects()](foundation/nsmutabledictionary/removeallobjects().md)
- [removeObjects(forKeys:)](foundation/nsmutabledictionary/removeobjects(forkeys:).md)

### Initializers

- [init(OBEXHeadersData:)](foundation/nsmutabledictionary/init(obexheadersdata:).md)
- [init(OBEXHeadersData:headersDataSize:)](foundation/nsmutabledictionary/init(obexheadersdata:headersdatasize:).md)
- [init(coder:)](foundation/nsmutabledictionary/init(coder:).md)

### Instance Methods

- [addApplicationParameterHeader(_:length:)](foundation/nsmutabledictionary/addapplicationparameterheader(_:length:).md)
- [addAuthorizationChallengeHeader(_:length:)](foundation/nsmutabledictionary/addauthorizationchallengeheader(_:length:).md)
- [addAuthorizationResponseHeader(_:length:)](foundation/nsmutabledictionary/addauthorizationresponseheader(_:length:).md)
- [addBodyHeader(_:length:endOfBody:)](foundation/nsmutabledictionary/addbodyheader(_:length:endofbody:).md)
- [addByteSequenceHeader(_:length:)](foundation/nsmutabledictionary/addbytesequenceheader(_:length:).md)
- [addConnectionIDHeader(_:length:)](foundation/nsmutabledictionary/addconnectionidheader(_:length:).md)
- [addCountHeader(_:)](foundation/nsmutabledictionary/addcountheader(_:).md)
- [addDescriptionHeader(_:)](foundation/nsmutabledictionary/adddescriptionheader(_:).md)
- [addHTTPHeader(_:length:)](foundation/nsmutabledictionary/addhttpheader(_:length:).md)
- [addImageDescriptorHeader(_:length:)](foundation/nsmutabledictionary/addimagedescriptorheader(_:length:).md)
- [addImageHandleHeader(_:)](foundation/nsmutabledictionary/addimagehandleheader(_:).md)
- [addLengthHeader(_:)](foundation/nsmutabledictionary/addlengthheader(_:).md)
- [addNameHeader(_:)](foundation/nsmutabledictionary/addnameheader(_:).md)
- [addObjectClassHeader(_:length:)](foundation/nsmutabledictionary/addobjectclassheader(_:length:).md)
- [addTargetHeader(_:length:)](foundation/nsmutabledictionary/addtargetheader(_:length:).md)
- [addTime4ByteHeader(_:)](foundation/nsmutabledictionary/addtime4byteheader(_:).md)
- [addTimeISOHeader(_:length:)](foundation/nsmutabledictionary/addtimeisoheader(_:length:).md)
- [addTypeHeader(_:)](foundation/nsmutabledictionary/addtypeheader(_:).md)
- [addUserDefinedHeader(_:length:)](foundation/nsmutabledictionary/adduserdefinedheader(_:length:).md)
- [addWhoHeader(_:length:)](foundation/nsmutabledictionary/addwhoheader(_:length:).md)
- [getHeaderBytes()](foundation/nsmutabledictionary/getheaderbytes().md)

### Default Implementations

- [NSDictionary Implementations](foundation/nsmutabledictionary/nsdictionary-implementations.md)
- [NSMutableDictionary Implementations](foundation/nsmutabledictionary/nsmutabledictionary-implementations.md)

## Relationships

### Inherits From

- [NSDictionary](foundation/nsdictionary.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomReflectable](swift/customreflectable.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [ExpressibleByDictionaryLiteral](swift/expressiblebydictionaryliteral.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSFastEnumeration](foundation/nsfastenumeration.md)
- [NSMutableCopying](foundation/nsmutablecopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [Sequence](swift/sequence.md)
