0

I have an object with a dictionary property. I want to sort by a value in the dictionary, lets say,

myObject.dictionary[@"sort"]

I have an array of these objects. Is it possible to create an NSSortDescriptor to sort by that value? Like,

[NSSortDescriptor sortDescriptorWithKey:@"dictionary['sort']" ascending:YES]
kailoon
  • 2,131
  • 1
  • 18
  • 33

1 Answers1

3

Yes, it's possible and very normal to sort an array of objects like that. You can simply create the sort descriptor in the following way:

NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:@"dictionary.sort" ascending:YES];

"dictionary.sort" will be used as keyPath for sorting your object.

utogaria
  • 3,662
  • 2
  • 14
  • 12
  • Thanks! That worked. This must be some sort of inherent knowledge of key/value coding because I couldn't find this documented anywhere. – kailoon Aug 05 '15 at 17:24