“Cannot assign value of type ‘String’ to type ‘AnyObject?'”, Swift 3, Xcode 8 beta 6

In b6, String no longer magically bridges to NSString. String is not a class; it’s a struct. You need to do the bridging by hand:

dict["key"] = "value" as AnyObject

The fact that is still seems to be bridging is likely a bug and should be reported.

It goes without saying that [String: AnyObject] and [String: Any] should be used as little as possible in your code.

(Make sure to follow the link Hamish provides in the comments below.)

Leave a Comment