排序NSDictionary [英] Sorting NSDictionary

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

问题描述

我想知道是否有人可以告诉我如何排序 NSDictionary ;我想从最后一个条目开始读取,因为键是Date + Time,我想能够将它附加到 NSMutableString

I was wondering if someone can show me how to sort an NSDictionary; I want to read it starting from the last entry, since the key is Date + Time and I want to be able to append it to an NSMutableString. I was able to read it using an enumerator but I don't get the results I want.

感谢

推荐答案

对于你的要求,最简单的方法是从键创建一个新数组,排序,然后使用数组来引用原始字典中的项目。

For your requirements the easiest way is to create a new array from the keys, sort that, then use the array to reference items from the original dictionary.

(注意,我的比较是你自己的比较两个键的方法)。

(Note myComparison is your own method that will compare two keys).

NSMutableArray* tempArray = [NSMutableArray arrayWithArray:[myDict allKeys]]; 
[tempArray sortedArrayUsingSelector:@selector(myComparison:)];

for (Foo* f in tempArray)
{
  Value* val = [myDict objectForKey:f];
}

这篇关于排序NSDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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