Last active
January 18, 2021 17:23
-
-
Save holleB/7b5875b6881a355f5b73feab8564b8a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mydict = ["a" : [1, 2, 3]] | |
mydict["a"]!.append(4) | |
// compiles and seems to work | |
var mydict2 : [String : Any] = ["a" : [1, 2, 3]] | |
mydict2["a"]!.append(4) // does not work. thats expected | |
(mydict2["a"] as! [Int]).append(4) | |
// does not work, unexpected for me. stackoverflow says that's because forcecasting value types | |
// creates a copy which is immutable | |
// how do I append to the array? | |
var el = mydict2["a"] as! [Int] | |
el.append(4) | |
mydict2["a"] = el | |
// that's seems overblown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment