I am implementing a protocol and providing some optional methods in swift but then I am implement these optional methods in derived class. When I call a protocol method it is calling extension method not the derived class method.
protocol ProtocolA {
func method1()
// Optional
func method2()
}
extension ProtocolA {
func method2(){
// It comes here, instead of class B method2.
print("In method 2 - Protocol A")
}
}
class A : ProtocolA {
func method1() {
print("In method 1 - class A")
}
}
class B : A {
func method2() {
print("In method 2 - Class B")
}
}
var a : A = B()
// It should call - In method 2 - Class B but the output is "In method 2 - Protocol A"
a.method2()