You may not understand what the keysSortedByValue:... method keysSortedByValue:... . It does not sort the keys (for this you just sorted the array returned by allKeys ), instead it sorts the values, and then applies their order to the keys.
So let's say you have the following dictionary:
{"Orange": 1, "Apple": 3, "Peach": 2}
Result:
"Orange", "Peach", "Apple"
since this corresponds to the sorted order of values (1, 2, 3).
source share