When do I add a value like "AnyObject?" into a dictionary of type '[String: AnyObject]' as follows, the value cannot be added, which is actually what I expected. Assigning an optional type to an optional type will not work in my opinion.
var myDict : [String : AnyObject] = [ "Key1" : "Value1" as AnyObject? ]
But why does this procedure work if I first initialize an empty dictionary and then add a value to it?
var myDict = [String : AnyObject]()
myDict["Key1"] = "Value1" as AnyObject?
I saw this approach in Apple's GenericKeychain example
https://developer.apple.com/library/content/samplecode/GenericKeychain/Introduction/Intro.html
source
share