ios - 是否可以为对象中的字典值创建 NSSortDescriptor?

标签 ios objective-c

我有一个带有字典属性的对象。我想按字典中的值排序,比方说,

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/

相关文章:

iphone - iOS - backbarButtonItem : Canceling back?

ios - NSDictionary 获取重复值

objective-c - 为什么 [NSDate date] 返回的时间与我当前的时间不同?

ios - 多个文本字段的键盘工具栏

iphone - 自定义 View Controller 委托(delegate)不起作用

ios - 在删除一行 UITableView 之前发出警告

ios - URLSession后台上传任务不断重置

objective-c - 如何重新加载 UICollectionView 补充 View (HeaderView)

iphone - 如何在多个类( View Controller )中使用 NSObject 类中的 NSString

ios - 带有 ios native 部分的 Realm 和 React Native