Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Contextual type 'AnyObject' cannot be used with dictionary literal

I am having difficulty constructing this dictionary. My code looks like this:

var array: [String] = []
let params: [String: AnyObject] = [
    "presentation": [
            "array": array,
            "current_index": 0
    ]
]

The error shows up on the first line "presentation": [ with Contextual type 'AnyObject' cannot be used with dictionary literal. I have tried rewriting the array, initializing the params then setting the values, etc. etc. and I cannot figure out this problem. Any help would be awesome!

Thank you in advance!

like image 460
Kiley Avatar asked Jun 28 '16 01:06

Kiley


2 Answers

Try this in swift 3 it works

var array: [String] = []
let params: [String: AnyObject] = [
    "presentation": [
            "array": array,
            "current_index": 0
    ] as AnyObject
]
like image 146
Arthi Avatar answered Sep 20 '22 01:09

Arthi


Try this

let params: [String: [String: AnyObject]]

And close the quotes after the current_index key.

like image 23
Davyd Geyl Avatar answered Sep 22 '22 01:09

Davyd Geyl