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

# keysSortedByValue(using:)

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

## Declaration

```swift
func keysSortedByValue(using comparator: Selector) -> [Any]
```

## Parameters

- `comparator`: A selector that specifies the method to use to compare the values in the dictionary. The comparator method should return NSOrderedAscending if the dictionary value is smaller than the argument, NSOrderedDescending if the dictionary value is larger than the argument, and NSOrderedSame if they are equal.

## 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.

## Discussion

Discussion Pairs of dictionary values are compared using the comparison method specified by comparator; the comparator message is sent to one of the values and has as its single argument the other value from the dictionary.

## See Also

### Related Documentation

- [allKeys](foundation/nsdictionary/allkeys.md)
- [sortedArray(using:)](foundation/nsarray/sortedarray(using:)-9nhh9.md)

### Sorting Dictionaries

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