Reputation:
I'm trying to wrap my head around the Swift Dictionary / multi-dimensional array syntax. I'm trying to initialize tableData
and insert a new tableData.myList
object using:
var tableData = ["myNumber":nil, "myList":[]]
tableData["myList"].insert(["label" : "Example Label A", "timestamp" : NSDate()], at: 0)
Which generates this error:
Value of type 'Array<Any>??' has no member 'insert'
Here's a sort of javascript sketch of what I'm trying to do: https://jsfiddle.net/L9s5amer/
Upvotes: 1
Views: 99
Reputation: 483
You should focus on an approach more generic:
var tableData: [String: Any?] = ["myNumber": nil, "myList": [Any]()]
var value = tableData["myList"] as? [Any]
value?.insert(["label" : "Example Label A", "timestamp" : NSDate()], at: 0)
tableData["myList"] = value
Upvotes: 0