Implementing and sorting associative array in Objective-C
In many languages, like PHP, there is what's known as associative array, that is, an array that consists of Key=>Value pairs, that can be sorted according to keys or to values. my question is:
- is the NSDictionary object the easiest way to create such array ?
- if yes, is there a ready method to sort an NSDictionary object according to values it holds (of course, while开发者_开发知识库 maintaining key=>value relationship, that is, the right key stays with the right value after the sort ends), plus I found this methos keysSortedByValueUsingSelector(@compare:) but it sorts according to keys only.
thanks for help
Ok, if everyone insists (see comments) ;)
You should read again: Returns an array of the dictionary’s keys, in the order they would be in if the dictionary were sorted by its values using...
So it does not sort by keys. It sorts by values and returns the keys in the corresponding order.
You can sort the keys by getting them first (allKeys) and then sort them.
精彩评论