字典值在同一订单指数雨燕1.2钥匙 [英] dictionary value and keys in same order index Swift 1.2
本文介绍了字典值在同一订单指数雨燕1.2钥匙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试试这个
let dict: [String:String] = ["1":"one","2":"two","3":"three","4":"four"]
let keyArray = [String](dict.keys)
let valueArray = [String](dict.values)
println(dict)
println(keyArray)
println(valueArray)
我希望的结果应该是
i hope the result should be
//dict = ["1":"one","2":"two","3":"three","4":"four"]
//keyArray = ["1","2","3","4"]
//valueArray = ["one","two","three","four"]
但它不是为
//dict = ["4": "four", "2": "two", "1": "one", "3":"three"]
//keyArray = ["4","2","1","3"]
//valueArray = ["four", "two", "one", "three"]
我如何得到我希望的结果。
How do I get my hope result
感谢您的任何帮助。
推荐答案
从斯威夫特语言指南
的的集合在同类型的密钥和相同类型的值之间的字典中存储的关联的没有定义排序
如果你想要一个样订货,拿到钥匙,命令他们,并得到相应的值。
If you want a kind of ordering, get the keys, order them and get the associated values.
有自定义类 OrderedDictionary
在GitHub上有一个底层实现数组的钥匙,以保持秩序。
There are custom classes OrderedDictionary
on GitHub with a backing array for the keys to keep the order.
这篇关于字典值在同一订单指数雨燕1.2钥匙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文