How Does AnyObject Conform to NSObjectProtocol?
问题 This question was inspired by mz2's answer on the question Check for object type fails with "is not a type" error. Consider an empty Swift class: class MyClass { } Attempting to call any NSObjectProtocol methods on an instance of this class will result in a compile-time error: let obj = MyClass() obj.isKindOfClass(MyClass.self) // Error: Value of type 'MyClass' has no member 'isKindOfClass' However, if I cast the instance as AnyObject , my object now conforms to NSObjectProtocol and I can