0

I have a function defined below:

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...
}

Where ret can be:

[[“name”: “NameA”, “gateways”: [[“id”: “ID1”, “name”: “Name1”], [“id”: “ID2”, “name”: “Name2”]]]]

and element can be

[“name”: “NameB”, “gateways”: [[“id”: “ID3”, “name”: “Name3”], [“id”: “ID4”, “name”: “Name4”]]]

The error that I got is Cannot subscript a value type of '[Dictionary<String, AnyObject>]' with an index of type 'String'.

I have referenced to some threads here but it still does not wipe out this error.

Please show me how.

Thanks

quanguyen
  • 1,443
  • 3
  • 17
  • 29

1 Answers1

0

Oh I see.

In my function, ret is an Array, not a Dictionary.

quanguyen
  • 1,443
  • 3
  • 17
  • 29