Given a very simple protocol :
protocol TheProtocol {
func doSomething()
func doSomethingElse()
func doThis()
func doThat()
}
I have a class Base that has a delegate waiting to be set.
// Can't modify this class at all
class Base {
public var delegate: TheProtocol?
}
My second class B inherits from this class Base, and implements TheProtocol in order to set the delegate to itself.
class B: Base, TheProtocol {
override init() {
super.init()
self.delegate = self
}
func doSomething() {
}
func doSomethingElse() {
}
... other methods to implement
}
Now what I want to be able to do, is to have a last class C, that contains an instance of B, and also set the delegate. I want the delegate to work both inside B and C.
The major constraint is that I can't modify the Base class.
class C: TheProtocol {
var obj = B()
init() {
// If I do this it won't fire within B anymore
obj.delegate = self
}
func doSomething() {
}
func doSomethingElse() {
}
... other methods to implement
}