---
title: "init(sharedKeySet:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsmutabledictionary/init(sharedkeyset:)"
---

# init(sharedKeySet:)

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

## Declaration

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

## Parameters

- `keyset`: The keyset, created by the doc://com.apple.foundation/documentation/Foundation/NSDictionary class method doc://com.apple.foundation/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

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

## Discussion

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

## See Also

### Creating and Initializing a Mutable Dictionary

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