---
title: "allKeys(for:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdictionary/allkeys(for:)"
---

# allKeys(for:)

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

## Declaration

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

## Parameters

- `anObject`: The value to look for in the dictionary.

## Return Value

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

Discussion Each object in the dictionary is sent an isEqual(_:) message to determine if it’s equal to anObject.

## See Also

### Accessing Keys and Values

- [allKeys](foundation/nsdictionary/allkeys.md)
- [allValues](foundation/nsdictionary/allvalues.md)
- [value(forKey:)](foundation/nsdictionary/value(forkey:).md)
- [objects(forKeys:notFoundMarker:)](foundation/nsdictionary/objects(forkeys:notfoundmarker:).md)
- [object(forKey:)](foundation/nsdictionary/object(forkey:).md)
- [subscript(_:)](foundation/nsdictionary/subscript(_:)-52n56.md)
- [subscript(_:)](foundation/nsdictionary/subscript(_:)-1bt1b.md)
