iOS*_*vil 68 sorting objective-c nsdictionary nsarray ios
我正在努力尝试排序一系列字典.
我的词典有一些兴趣,价格,受欢迎程度等值.
有什么建议?
War*_*ior 200
NSSortDescriptor
像这样使用..
NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES];
stories = [stories sortedArrayUsingDescriptors:@[descriptor]];
recent = [stories copy];
Run Code Online (Sandbox Code Playgroud)
stories
是要排序的数组.recent
是另一个可变数组,它已经对字典值进行了排序.@"interest"
使用您必须排序的键值更改.
祝一切顺利
sup*_*org 25
[array sortUsingDescriptors:[NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:@"YOUR-KEY" ascending:YES], nil]];
Run Code Online (Sandbox Code Playgroud)
我真的不想把它分成多行.这对我来说已经很简单了.
Ans*_*ais 11
您只需从父级遍历到所需的子属性即可.例如
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"parent.child.child" ascending:YES];
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
44198 次 |
最近记录: |