如何对包含NSDictionaries的NSArray进行排序? [英] How can I sort an NSArray containing NSDictionaries?

查看:80
本文介绍了如何对包含NSDictionaries的NSArray进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 NSArray ,其中包含 NSDictionary 对象。这些 NSDictionary 对象中的每一个都包含 ORDER 键。

I have an NSArray which contains NSDictionary objects. Each of these NSDictionary objects contains an ORDER key.

如何根据每个 NSDictionaries 中的此键对此 NSArray 进行排序?

How can I sort this NSArray based on this key within each of these NSDictionaries?

推荐答案

这是一个例子。想象一下,你有一系列的字典。 Ecah dictionnary有2个键name& 出生日期。您可以通过名称对数组进行排序,如下所示:

Here is an example. Imagines you have an array of dictionnaries. Ecah dictionnary have 2 keys "name" & "dateOfBirth". You can sort your array by "name" like this :

//
// Sort array by name
//
NSSortDescriptor *Sorter = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:Sorter]];
[Sorter release];

请注意 myArray 的NSMutableArray

这篇关于如何对包含NSDictionaries的NSArray进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆