为什么NSDictionary在内存中是字母顺序的,但在枚举中却不是字母顺序的? [英] Why is NSDictionary alphabetical in memory, but not in enumeration?

查看:106
本文介绍了为什么NSDictionary在内存中是字母顺序的,但在枚举中却不是字母顺序的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道排序NSDictionary的正确方法是从键创建一个数组,对该数组进行排序,然后枚举该数组并从那里对NSDictionary进行操作.我的问题是,对于NSDictionary * dict,具有键和字符串值,

I understand that the right way to sort an NSDictionary is to create an array from the keys, sort the array, and then enumerate through the array and operate on the NSDictionary from there. My question is, for an NSDictionary *dict, with keys and values of strings,

为什么这是字母顺序:

NSLog(@"%@", dict);

但这不是:

for (NSString *w in dict)
{
    NSLog(@"%@", w);
}

似乎很奇怪...我在做错什么吗?

Seems odd... am I doing something wrong?

谢谢.

推荐答案

这不是在内存中"-%@导致对字典调用消息,并对消息进行排序.枚举旨在使您以最快的速度访问原始内容.如果需要对其进行排序,则必须对其进行排序.

That's not "in memory" -- %@ causes a message to be called on dict, and that sorted it. Enumerating is meant to give you the fastest, raw access to the contents. If you need it sorted, you have to sort it.

看看这个免费的Objective-C字典

Take a look at this free sorted dictionary for Objective-C

http://code.google.com/p/cocoa-sorted-dictionary/

这篇关于为什么NSDictionary在内存中是字母顺序的,但在枚举中却不是字母顺序的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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