Tôi không chắc chắn, có vẻ như với tôi rằng đó là một loại lỗi hoặc triển khai không đúng với các phần mở rộng giao thức trong Swift 2.0.Swift 2, mở rộng giao thức & respondsToSelector
Tôi có giao thứcA, giao thứcB mở rộng giao thứcA và các phương thức triển khai trong phần mở rộng protocolB.
Tôi đã tuân thủ một cá thể lớp để phù hợp với protocolB, tuy nhiên khi được kiểm tra bởi respondsToSelector cho các phương thức protocolA/B thì kết quả là sai.
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**
}
Báo cáo là lỗi?
Bạn nên gửi lỗi. – Laurent
Yup. Bạn đã gửi một lỗi chưa? :) – tadija
Có, thực sự đó là một lỗi. Bạn đã xảy ra để nộp nó? – csotiriou