Can you explain this Swift code
If I assign nil value for "a" key and then use if let statement this nil value will be unwrapped as nil and can be printed
import Foundation
var dictionary = ["a": nil, "b": "Costam", "c": nil]
dictionary.updateValue(nil, forKey: "a")
if let value = dictionary["b"] {
print("Some value: ", value)
}
print(dictionary.keys)
And to prevent this behaviour I need to add typecasting to String?
import Foundation
var dictionary = ["a": nil, "b": "Costam", "c": nil]
dictionary.updateValue(nil, forKey: "a")
if let value = dictionary["b"] as? String {
print("Some value: ", value)
}
print(dictionary.keys)