我不确定,在我看来,它是
Swift 2.0中的协议扩展的某种错误或不良实现.
原文链接:https://www.f2er.com/swift/318686.html我有protocolA,protocolB扩展protocolA和protocolB扩展中的实现方法.
我已经使类实例符合protocolB,但是当respondsToSelector检查protocolA / B方法时,结果是错误的.
import Cocoa import XCPlayground protocol ProtocolA : NSObjectProtocol { func functionA() } protocol ProtocolB : ProtocolA { func functionB() } extension ProtocolB { func functionA() { print("Passed functionA") } func functionB() { print("Passed functionB") } } class TestClass : NSObject,ProtocolB { override init () { } } var instance:TestClass = TestClass() instance.functionA() // Calls code OK.. if instance.respondsToSelector("functionA") { print("Responds to functionA") // **False,never passing here** } if instance.respondsToSelector("functionB") { print("Responds to functionB") // **False,never passing here** }
应该报告为bug?