-1

If I have an NSMutableDictionary keys {B,A,D,C} and values {custom obj1, custom obj2, custom obj3, custom obj4},

I would like this to sort into

{A,B,C,D} -> {custom obj2, custom obj1, custom obj4, custom obj3}
Apollo
  • 8,874
  • 32
  • 104
  • 192
  • 1
    You can't sort a dictionary. You can sort the keys and then access the objects based on the sorted keys. – rmaddy Apr 11 '14 at 03:22
  • 2
    possible duplicate of [how can I sort NSMutableDictionary with keys value?](http://stackoverflow.com/questions/8118932/how-can-i-sort-nsmutabledictionary-with-keys-value) – rmaddy Apr 11 '14 at 03:22

1 Answers1

0

You can't sort dictionaries themselves. However you can get the key array [dictionary allKeys] and sort that. Something like:

NSMutableArray mutableKeys = [[dictionary allKeys] mutableCopy];
[mutableKeys desiredSortingMethod];
Murillo
  • 1,043
  • 8
  • 9