NSMutableDictionary 枚举
我使用对象和键 NSEnumerator 来查看字典,我注意到它改变了它枚举字典的顺序。我觉得这很烦人。有没有办法获取 NSEnumerator 对象或键,以按照我创建它的顺序进行查看?将其格式化为 NSArray 不是一个选项。
I used both object and key NSEnumerators to look through a dictionary and I noticed that it changes the order in which it enumerates through the dictionary. I find that rather annoying. Is there a way to get the NSEnumerator object or key, to look through in the order in which I created it? Formatting it into an NSArray isn't an option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字典本质上不是有序集,因此以何种顺序存储数据并不重要。您可以使用 nsarray 并将密钥存储在其中,然后按照该数组中存储的顺序从字典中调用对象。
a dictionary is inherently not an ordered set so it doesn't matter in which order you store your data in it. you could use an nsarray and store your keys in it and then invoke your objects from the dictionary in the order stored in that array.
去年通过这个线程找到的,你会发现一个很好的OrderedDictionary类此处
found via this thread last year, you'll find a good OrderedDictionary class here