NSDictionary返回值问题
我从 NSDictionary 对象创建一个数组:
NSarray *myarray=[dictionary allValues];
但是索引处的返回数组对象并不根据字典,例如字典中的第一个对象是“title”,但在我的数组中它返回联系号码,为什么会发生这种情况以及如何防止?
另外,当我将对象设置为字典时,它会弄乱队列:
[item setObject:@"title" forKey:@"title"];
[item setObject:@"1997" forKey:@"year"];
[item setObject:@"history" forKey:@"summary"];
但是当我在控制台中打印出该字典时,第一个对象成为历史,第二个对象成为年份,最后一个对象成为标题,它是如何以及为什么会发生?我是否错过了关于 NSDictionay 的任何事情,以前有人遇到过这个问题吗?
i create a array from a NSDictionary object:
NSarray *myarray=[dictionary allValues];
however the return array object at index is not according to the dictionary, for instance the first object in dictionary was "title", but in my array it returned contact number, why this happended and how to prevent?
also when i set the object to my Dictionary it mess up the queue for instance:
[item setObject:@"title" forKey:@"title"];
[item setObject:@"1997" forKey:@"year"];
[item setObject:@"history" forKey:@"summary"];
but when i printed out this dictionary in console, the first object was become history, second become year, and last was title,how and why it could happen?am i miss anything thing i should now about NSDictionay, have anybody meet this problem before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSDictionary 不维护顺序。
NSArray是有序的,但它的数据来自无序字典。
另请参阅: 带有有序键的 NSDictionary
NSDictionary does not maintain order.
The NSArray is ordered, but its data comes from the un-ordered dictionary.
See also: NSDictionary with ordered keys
我已经维护了 NSDictionary 的原始顺序。
感谢 Matt Gallaghers orderedDictionary 课
I have done maintain original order of NSDictionary.
Thanks to matt gallaghers orderedDictionary class