[swift-users] Dictionary with optional values
Artyom Goncharov
swift-users_me at mayerscraft.com
Wed May 18 05:56:40 CDT 2016
Hi, here is the playground snippet:
var noOptDict = ["one": 1, "two": 2, "three": 3 ]
noOptDict["one"] = nil
noOptDict // “one” is gone
var optDict: [String: Int?] = ["one": 1, "two": 2, "three": nil]
optDict["one"] = nil
optDict // “one” is gone but “three” is still there
So the first dict instance works as it should, the second using opt values allows to store nil but deletes the key when you assign nil. Is it bug, feature, or both?
Best wishes,
Artyom
More information about the swift-users
mailing list