【发布时间】:2020-05-04 19:55:06
【问题描述】:
我在这里查看了其他下标问题,但我认为它们与我的问题不符。我有一本字典 - Dictionary[String:Dictionary[String:String]]
在一个扩展中,我想遍历所有值 (Dictionary[String:String] 并检索其中一个值。
所以我写了这个:
for dictNEO in Array(self.values) {
print(dictNEO)
print(type(of: dictNEO))
print(dictNEO["approachDate"])
}
我在最后一行打印出这个错误:Value of type 'Value' has no subscripts
这是前两行打印:
["nominalDist": "\"13.58 ", "approachDate": "\"2020-Feb-01 08:18 ± < 00:01\"", "minimumDist": "\"13.58 ", "diameter": "\"92 m - 210 m\"", "name": "\"(2017 AE5)\""]
Dictionary<String, String>
所以我很困惑为什么它在将类型视为字典时告诉我它没有下标。
【问题讨论】:
-
您能否编辑您的问题并详细说明“在扩展中” - 显示您如何指定扩展。另外,您正在尝试使用哪个版本的 Swift?这应该可以帮助人们帮助你。
标签: swift dictionary subscript