I have this code in Swift:
var dictionary: [String: Any?]?
fileprivate func value(forKey key: Key) -> Any? {
if let dictionary = self.dictionary {
return dictionary[key.rawValue]
}
...
}
I get a warning "Expression implicitly coerced from 'Any??' to 'Any?' in the return statement ". What am I doing wrong?
The value of your dictionary is Any?. The result of accessing a dictionary value is an optional because the key might not exist. So you end up with Any??.
There's really no need for your dictionary to be declared to have optional values.
Change it to [String: Any]? and your issue goes away.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With