Swift append an array when it's been declared as Any I'm learning Swift and I have a following problem: I create a dictionary containing some data, one of which is stored as an array. I want make an operation on this array to add some info. Currently I have managed to achieve this by writing this code:

var myDictionary = [String: Any]()

myDictionary = [
    "name": "Wiktor",
    "age": 25,
    "scores": [1, 2, 3, 4, 5, 6],
]

var l = myDictionary["scores"] as? [Int] ?? [Int]()
l.append(100)
myDictionary["scores"] = l
print("\(myDictionary["scores"]!)")


This works, meaning an array with value 100 is printed out, but this solution seems a little bit over engineered to me. Can I do it easier, more like:

myDictionary["scores"].append(100)


in python?
Since myDictionary values are declared as Any, you could have anything (or even nothing) assigned at "scores", so you need to safe-cast the value in to a variable first and then reassign it.

I don't know about Python, but Swift doesn't check dictionary values at compile time.