<!--
{
  "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/NSDictionary/sharedKeySet(forKeys:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(cm)sharedKeySetForKeys:"
  },
  "title" : "sharedKeySet(forKeys:)"
}
-->

# sharedKeySet(forKeys:)

Creates a shared key set object for the specified keys.

```
class func sharedKeySet(forKeys keys: [any NSCopying]) -> Any
```

## Parameters

`keys`

The array of keys. If the parameter is nil, an exception is thrown. If the array of keys is empty, an empty key set is returned.

## Return Value

A shared key set object.

## Discussion

The array of `keys` may contain duplicates which are quietly ignored. Duplicate hash values of the keys are quietly allowed, but may cause lower performance and increase memory usage.

Typically you would create a shared key set for a given set of keys once, before creating shared key dictionaries, and retain and save the result of this method for use with the [`NSMutableDictionary`](/documentation/Foundation/NSMutableDictionary) class method `dictionaryWithSharedKeySet:.`

---

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)