排序NSD阵列NSDrray对象的最佳方法? [英] Best way to sort an NSArray of NSDictionary objects?

查看:76
本文介绍了排序NSD阵列NSDrray对象的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力尝试对一系列词典进行排序。

I'm struggling with trying to sort an array of dictionaries.

我的词典有一些兴趣,价格,受欢迎程度等值。

My dictionaries have a couple of values of interest, price, popularity etc.

有任何建议吗?

推荐答案

使用 NSSortDescriptor 喜欢这个..

NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES];
stories = [stories sortedArrayUsingDescriptors:@[descriptor]];
recent = [stories copy];

故事是您要排序的数组。 最近是另一个可变数组,它已经对字典值进行了排序。使用您必须对其进行排序的键值更改 @interest

stories is the array you want to sort. recent is another mutable array which has sorted dictionary values. Change the @"interest" with the key value on which you have to sort.

一切顺利

这篇关于排序NSD阵列NSDrray对象的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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