I was a few days ago from Objective-C to write Swift language, in the project I have encountered a problem.This problem is when using respondsToSelector ("testEnum:") function to check whether to implement the function of the testEnum:,if the param is the case, it will return false, I have tried other types, it will return true, do not know what is the reason, see the following code, to help me solve it, thank you very much!
enum TestEnum {
case A
case B
case C
}
protocol TestAProtocol: NSObjectProtocol {
func testEnum(testEnum: TestEnum);
func testInt(testInt: Int);
}
class TestA: NSObject {
var delegate: TestAProtocol?;
func executeDelegateCallBack() {
if (delegate != nil && delegate!.respondsToSelector(Selector("testEnum:"))) { // delegate!.respondsToSelector(Selector("testEnum:")) return false ?
delegate?.testEnum(TestEnum.A);
}
if (delegate != nil && delegate!.respondsToSelector(Selector("testInt:"))) { // delegate!.respondsToSelector(Selector("testInt:")) return true ?
delegate?.testInt(0);
}
}
}
class TestB: NSObject, TestAProtocol {
func initTestB () {
let testA: TestA = TestA();
testA.delegate = self;
testA.executeDelegateCallBack();
}
// mark TestAProtocol
func testInt(testInt: Int) {
}
func testEnum(testEnum: TestEnum) {
}
}