如何声明一个以数组为值的字典?这可能吗?
最佳答案
是
let myDictionary: [String: [Int]] = ["Hello": [1, 2, 3], "World": [4, 5, 6]]
事实上,如果您就地分配初始值,您甚至不需要显式类型声明。它可以很简单:
let myDictionary = ["Hello": [1, 2, 3], "World": [4, 5, 6]]
使用值:
println(myDictionary["Hello"][0]) // Print 1
println(myDictionary["World"][0]) // Print 4
关于ios - 以数组为值的 Swift 字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27066485/