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

# keysSortedByValue(options:usingComparator:)

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 and a specified set of options.

## Declaration

```swift
func keysSortedByValue(options opts: NSSortOptions = [], usingComparator cmptr: (Any, Any) -> ComparisonResult) -> [Any]
```

## Parameters

- `opts`: A bitmask of sort options.
- `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 with the options given in opts.

## See Also

### Sorting Dictionaries

- [keysSortedByValue(using:)](foundation/nsdictionary/keyssortedbyvalue(using:).md)
- [keysSortedByValue(comparator:)](foundation/nsdictionary/keyssortedbyvalue(comparator:).md)
