一个相当简单的代码片段
原文链接:https://www.f2er.com/swift/320645.htmlvar dict: [String: AnyObject] = [:] dict["key"] = "value"
Cannot assign value of type 'String' to type 'AnyObject?'
简单的类型检查告诉我,String是AnyObject
"value" is AnyObject // returns true
我可以将AnyObject更改为Any,一切都可以正常工作
var dict: [String: Any] = [:] dict["key"] = "value"
但是我想明白为什么我会收到错误? String不再是AnyObject吗?还是这个bug?