Consider this (rather tedious) code :
class SCell : NSObject {}
class SHeader : NSObject {}
class Cell : SCell {}
class Header : SHeader {}
struct Model {}
protocol PA {
typealias Ce = SCell
typealias He = SHeader
func doThis(cell : PA.Ce,header : PA.He)
}
extension PA {
func doThis(cell : PA.Ce,header : PA.He) {
print("A's implementation")
}
}
protocol PB:PA {
}
extension PB {
func doThis(cell : PA.Ce,header : PA.He) {
print("B's implementation")
}
}
class A : PA {
func doSomethingElse() {
self.doThis(cell: Cell(), header: Header())
}
}
class B : A,PB {
}
class C : B {}
let c = C()
c.doSomethingElse()
To my surprise, this started printing out
"A's implementation"
I was expecting it to print "B's implementation" since doThis(cell:header) is overridden as a part of PBs default implementation. This surprisingly did not happen.
What's more interesting is that if I do this:
class B: A,PB {
override func doSomethingElse() {
self.doThis(cell: Cell(), header: Header())
}
}
It started to print out
B's implementation
Why is this happening?