Swift: Contextual type 'AnyObject' cannot be used with dictionary literal
10,099
Solution 1
Try this
let params: [String: [String: AnyObject]]
And close the quotes after the current_index
key.
Solution 2
Try this in swift 3 it works
var array: [String] = []
let params: [String: AnyObject] = [
"presentation": [
"array": array,
"current_index": 0
] as AnyObject
]
Author by
Kiley
This user prefers to keep an air of mystery about them...
Updated on August 17, 2022Comments
-
Kiley over 1 year
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!