---
title: "keysSortedByValue(comparator:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsdictionary/keyssortedbyvalue(comparator:)"
---

# keysSortedByValue(comparator:)

Returns an array of the dictionary’s keys, in the order they would be in if the dictionary were sorted by its values using a given comparator block.

## Declaration

```swift
func keysSortedByValue(comparator cmptr: (Any, Any) -> ComparisonResult) -> [Any]
```

## Parameters

- `cmptr`: A comparator block.

## Return Value

Return Value An array of the dictionary’s keys, in the order they would be in if the dictionary were sorted by its values using cmptr.

## See Also

### Sorting Dictionaries

- [keysSortedByValue(using:)](foundation/nsdictionary/keyssortedbyvalue(using:).md)
- [keysSortedByValue(options:usingComparator:)](foundation/nsdictionary/keyssortedbyvalue(options:usingcomparator:).md)
