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
func keysSortedByValue(using comparator: Selector) -> [Any]Parameters
- comparator:
A selector that specifies the method to use to compare the values in the dictionary.
The
comparatormethod should returnNSOrderedAscendingif the dictionary value is smaller than the argument,NSOrderedDescendingif the dictionary value is larger than the argument, andNSOrderedSameif they are equal.
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
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.