我在 Swift 中有以下数组:
var words = [
"English" : ["Hello", "Bye"],
"Spanish" : ["Hola", "Adios"]
]
我怎样才能得到索引的值,下面的东西不起作用
print(words["English"][0])
它抛出错误:可选类型数组的值?没有解开,你的意思是使用!或者 ?但这就是它:
print(words["English"]?[0])
还是不行,请帮忙。
最佳答案
你需要研究如何unwrap optionals .例如,您尝试做的事情可以通过以下两种方式之一完成:
强制展开:
print(words["English"]![0])
安全解包:
if let hello = words["English"]?[0]{
print(hello)
}
关于swift - 快速从多维数组中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45292349/