<!--
{
  "availability" : [
    "iOS: 6.0.0 -",
    "iPadOS: 6.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.8.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMutableDictionary/init(sharedKeySet:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMutableDictionary(cm)dictionaryWithSharedKeySet:"
  },
  "title" : "init(sharedKeySet:)"
}
-->

# init(sharedKeySet:)

Creates a mutable dictionary which is optimized for dealing with a known set of keys.

```
init(sharedKeySet keyset: Any)
```

## Parameters

`keyset`

The `keyset`, created by the [`NSDictionary`](/documentation/Foundation/NSDictionary) class method [`sharedKeySet(forKeys:)`](/documentation/Foundation/NSDictionary/sharedKeySet(forKeys:)).
  
  > Important:
  > If `keyset` is `nil`, an exception is raised. If `keyset` is not an object returned by ``doc://com.apple.foundation/documentation/Foundation/NSDictionary/sharedKeySet(forKeys:)``, an exception is raised.

## Return Value

A new mutable dictionary optimized for a known set of keys.

## Discussion

Keys that are not in the key set can still be set in the dictionary, but that usage is not optimal.

---

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)