I have declared following dictionary
var locations:Dictionary<String,String> = ["loc1":"Los Angeles","loc2":"San Francisco"];
then trying to simply assign it to a variable rather than a constant
var location:String = locations["loc1"];
but then the compiler is complaining about : Value of optional type 'String?' not unwrapped; did you mean to use '!' or '?'?
If I change var location:String = locations["loc1"]; to var location:String? = locations["loc1"]; ,which means the String is optional, compiler error goes away.
but as you can see I haven't defined my dictionary to be optional e.g. Dictionary<String,String?>. So just wondering why does Swift convert my value type to be optional string(String?) behind the scene?