如何对包含字典的数组进行排序? [英] How to sort an array which contains Dictionaries?
本文介绍了如何对包含字典的数组进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含字典的数组;那么如何根据字典键值对数组进行排序?
I have an array which contains dictionaries in it; so how can I sort the array according to dictionary key values?
推荐答案
如果数组中的每个元素都是包含特定键的字典,则可以使用排序描述符对数组进行排序.例如,如果每个元素都是包含名为名称"的键的字典:
If every element in the array is a dictionary containing a certain key, you can sort the array using a sort descriptor. For instance, if every element is a dictionary containing a key called "name":
NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortByName];
NSArray *sortedArray = [array sortedArrayUsingDescriptors:sortDescriptors];
这篇关于如何对包含字典的数组进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文