NSDictionary中的键和值是否有序? [英] Are keys and values in an NSDictionary ordered?

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

问题描述

我的意思是:NSDictionary中的键和值的顺序是否总是相同的,就像它们在初始化NSDictionary时指定的顺序一样?或者,如果我真的需要知道键的顺序,我应该更好地维护一个单独的NSArray?

I mean: Is the order of keys and values in an NSDictionary always the same like how they were specified when initializing the NSDictionary? Or should I better maintain a seperate NSArray if I really need to know the order of keys?

推荐答案

。只要您不添加或删除字典中的任何元素,它们将保持相同的顺序,但一旦添加或删除元素,新订单将完全不同。

No, they are not ordered. As long as you don't add or remove any elements from the dictionary, they will remain in the same order, but as soon as you add or remove an element, the new order will be completely different.

如果需要排序键/值,请改用NSArray(或其他有序数据结构)。

If you need the keys/values to be ordered, use an NSArray (or some other ordered data structure) instead.

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

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