我有一个带有字典属性的对象。我想按字典中的值排序,比方说,
myObject.dictionary[@"sort"]
我有这些对象的数组。是否可以创建一个 NSSortDescriptor 来按该值排序?喜欢,
[NSSortDescriptor sortDescriptorWithKey:@"dictionary['sort']" ascending:YES]
最佳答案
是的,像这样对一组对象进行排序是可能的,而且很正常。 您可以通过以下方式简单地创建排序描述符:
NSSortDescriptor *sorter = [NSSortDescriptor sortDescriptorWithKey:@"dictionary.sort" ascending:YES];
“dictionary.sort”将用作对对象进行排序的 keyPath。
关于ios - 是否可以为对象中的字典值创建 NSSortDescriptor?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31837864/