basically I have an NSDictionary with keys and values.
The keys are all numbers, but at the moment they are strings.
I want to be able to compare them as numbers in order to sort them.
eg: If I have a Dictionary like this:
{
"100" => (id)object,
"20" => (id)object,
"10" => (id)object,
"1000" => (id)object,
}
I want to be able to sort it like this:
{
"10" => (id)object,
"20" => (id)object,
"100" => (id)object,
"1000" => (id)object,
}
Any ideas?
Thanks
Tom
Use
compare:options:
withNSNumericSearch
.Not sure what you are up to – dictionaries are inherently unsorted, there is no stable key ordering in the default implementation. If you want to walk the values by sorted keys, you can do something like this:
You can't sort a dictionary, but you can get the keys as an array, sort that, then output in that order. sortedArrayUsingComparator will do that, and you can compare the strings with the NSNumericSearch option.