NSDictionary键顺序保证与初始化相同,如果它从来没有改变? [英] Is NSDictionary key order guaranteed the same as initialized if it never changes?

查看:541
本文介绍了NSDictionary键顺序保证与初始化相同,如果它从来没有改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题与此问题中发现的问题相同。但是,我有一个后续问题。我似乎在与原来的asker相同的情况:我有一个plist与字典的层次结构,定义一个配置屏幕。这些是 可变, 在整个应用程序中保持不变。因为原来的讨论似乎集中在由变异字典引起的问题,我必须要求确认:字典的顺序是否保证与plist中的顺序相同,即,它被读取(使用initWithContentsOfFile)?

I've run into the same problem as found in this question. However, I have a follow-up question. I seem to be in the same situation as the original asker: I have a plist with a hierarchy of dictionaries that define a configuration screen. These are not mutable and will stay the same throughout the application. Since the original discussion seems to focus on problems arising from mutating the dictionary, I must ask for comfirmation: is the order of a dictionary guaranteed the same as they are in the plist, i.e. as it is read (with initWithContentsOfFile)? Can I use allKeys on it in this case to get a correct-order array of keys if the dictionary never changes?

推荐答案

不能在这种情况下使用allKeys来获取正确顺序的键数组,键不太可能以与您的 plist 文件相同的顺序出现。我不能在引擎盖下面看,但我会猜测,按任何方式提供有效的查找键。 allKeys 说未定义数组中元素的顺序。

No, the keys are not likely to appear in the same order as your plist file. I can't look under the hood, but I would guess that the keys are ordered in whatever way that provides an efficient look-up. The documentation for allKeys says that the order of the elements in the array is not defined.

这篇关于NSDictionary键顺序保证与初始化相同,如果它从来没有改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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