Example:
Playground: github
protocol A: class {}
extension A {
func someFunc() {
print("1")
}
}
class B {
weak var delegate: A?
func someTrigger() {
delegate?.someFunc()
}
}
class C: A {
lazy var b: B = {
let b = B()
b.delegate = self
return b
}()
func someFunc() {
print("2")
}
init() {
b.someTrigger()
}
}
let c = C()
/// printed 1
Question
Here above you can see an example to better understand the question. So the question is: Can protocol be extended with function that would be defined by implementer(class that implements protocol)? In my opinion result of example code is unexpected. Can it be done in some way without protocol inheritance?
Update
I can't implement someFunc()
in protocol A
(it's UIKit
protocol). That is why I'm considering exactly this kind of architecture/configuration.