Type '[String, AnyObject?]' does not conform to protocol AnyObject?: why?
问题 I'm trying to understand why I have a compilation error: Type '[String, AnyObject?]' does not conform to protocol AnyObject? var cars: [String: AnyObject?] = [ "model": "Ferrari"] var JSON: [String: AnyObject?] = [ "cars": cars ] // <-- error It seems like cars is not an AnyObject? which I don't understand. Thanks for your help! 回答1: AnyObject must be a class, but Dictionary is a structure. The Swift Programming Language: Type Casting AnyObject can represent an instance of any class type. The