我学习swift并尝试创建简单(如js)字典,这将保留来自传入json的值。
var QUOTES: Dictionary<String, Dictionary<String, Any>>
var data: [Dictionary<String,Any>] = [
["ticker": "AAPL", "price": 100, "name": "Apple Company", "some": "something"],
["ticker": "F", "price": 150, "name": "Ford Company"],
["ticker": "FB", "price": 1000, "name": "Facebook Company"],
]
for quote in data {
var ticker = quote["ticker"] as! String
for (key, value) in quote {
QUOTES[ticker][key] = value //it fails with error
}
}
我收到错误:
可选类型的值&#39; [字符串:任意]?&#39;没有打开;你的意思是使用&#39;!&#39;或者&#39;?&#39;?
我已经阅读了展开价值所能做的一切,但是!
没有帮助。
我该怎么做才能填写所需的词典?