NSDictionary 排序
我想知道是否有人可以告诉我如何对 NSDictionary
进行排序;我想从最后一个条目开始阅读它,因为键是日期+时间,并且我希望能够将其附加到 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.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的要求,最简单的方法是从键创建一个新数组,对其进行排序,然后使用该数组引用原始字典中的项目。
(注意 myComparison 是您自己的方法,它将比较两个键)。
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).
我汇总了 StackOverflow 上关于将 NSDictionary 排序为非常紧凑且按字母顺序排序的其他建议。我在“路径”中有一个 Plist 文件,我将其加载到内存中并想要转储。
I've aggregated some of the other suggestions on StackOverflow on sorting an NSDictionary into something very compact that will sort alphabetically. I have a Plist file in 'path' that I load in to memory and want to dump.