【发布时间】:2016-09-29 05:54:25
【问题描述】:
我有一个函数定义如下:
private func append(inout ret: [Dictionary<String, AnyObject>]?, element: Dictionary<String, AnyObject>) {
if ret == nil {
ret = [Dictionary<String, AnyObject>]()
ret?.append(element)
return
}
let retGateways = ret!["gateways"] as! [Dictionary<String, AnyObject>] // ERROR: Cannot subscript...
// more commands...
}
ret 可以是:
[[“name”: “NameA”, “gateways”: [[“id”: “ID1”, “name”: “Name1”], [“id”: “ID2”, “name”: “Name2”]]]]
和element可以
[“name”: “NameB”, “gateways”: [[“id”: “ID3”, “name”: “Name3”], [“id”: “ID4”, “name”: “Name4”]]]
我得到的错误是Cannot subscript a value type of '[Dictionary<String, AnyObject>]' with an index of type 'String'。
我在这里引用了一些线程,但它仍然没有消除这个错误。
请告诉我怎么做。
谢谢
【问题讨论】:
标签: arrays dictionary subscript swift2.2