在视频教程中:
16 分钟快速无脚本教程介绍 Apple Swift 编程语言 http://youtu.be/3tZig9AWMdc?t=9m10s
我做了和他一样的事情,但结果却相反
var names = [
"1" : "...",
"2" : "...2"
]
for (k,v) in names {
println("key is \(k) : value is: \(v)")
}
输出:
Hello, World!
key is 2 : value is: ...2
key is 1 : value is: ...
我在这里缺少什么?
最佳答案
你什么都没有错过。
字典
是无序集合。
来自the docs :
Swift’s Dictionary type is an unordered collection. The order in which keys, values, and key-value pairs are retrieved when iterating over a dictionary is not specified.
关于字典向后打印结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44205884/