<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSDictionary/allKeys(for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSDictionary(im)allKeysForObject:"
  },
  "title" : "allKeys(for:)"
}
-->

# allKeys(for:)

Returns a new array containing the keys corresponding to all occurrences of a given object in the dictionary.

```
func allKeys(for anObject: Any) -> [Any]
```

## Parameters

`anObject`

The value to look for in the dictionary.

## Return Value

A new array containing the keys corresponding to all occurrences of `anObject` in the dictionary. If no object matching `anObject` is found, returns an empty array.

## Discussion

Each object in the dictionary is sent an <doc://com.apple.documentation/documentation/ObjectiveC/NSObjectProtocol/isEqual(_:)> message to determine if it’s equal to `anObject`.

---

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)