从 plist 读取数组时,NSArray / NSMutableArray 顺序是否得到保证?

发布于 2024-12-31 23:17:31 字数 447 浏览 2 评论 0原文

我有一个包含数组的 plist,其中有许多我不想按特定顺序维护的项目。

当我从 plist 创建 NSArray 时,该数组的对象顺序是否与 plist 相同?例如。如果我执行如下代码,数组中的项目是否与 plist 的顺序相同?

NSMutableDictionary* plistDictionary = [self someMethodToReadThePlistAsDictionary:plistName];
NSArray* array = [plistDictionary objectForKey:@"arrayKey"];

有任何文件可以验证这一点吗?在实践中似乎是这样,但我想以某种方式验证一下。

编辑:我似乎对这个问题投了反对票,所以让我澄清一下:我完全意识到数组维护插入顺序。我的问题与“plist”有关,因为我不知道当 plist 成为对象时会发生什么。

I have a plist containing an array, with a number of items that I wan't maintained in a particular order.

When I create an NSArray from the plist, will the array have the objects in the same order as the plist? For example. If I execute the code like the following, will the array have the items in the same order as the plist?

NSMutableDictionary* plistDictionary = [self someMethodToReadThePlistAsDictionary:plistName];
NSArray* array = [plistDictionary objectForKey:@"arrayKey"];

Is there any documentation where I can verify this? In practice it seems to be the case, but I would like to verify it somehow.

EDIT: I seem to be getting down votes for this question, so let me clarify: I am fully aware that an array maintains insertion order. My question has to do with "plists", since I am unaware of what happens to a plist when it becomes an object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫性小仙女 2025-01-07 23:17:31

答案是肯定的,数组元素的顺序将被保持 - 因为数组是项目的有序集合,就像字符串是字符的有序序列一样......

The answer is yes, the order of the elements of an array will be maintained - because an array is an ordered collection of items, just like a string is an ordered sequence of characters...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文