Consider the following:
protocol ViewControllable: class {
typealias VM: ViewModellable
var vm: VM! { get }
func bind()
}
extension ViewControllable {
var vm: VM! {
didSet {
bind()
}
}
}
I'm trying to observe vm
property and call bind
whenever it is injected. But this doesn't compile with error saying:
Extensions may not contain stored properties
which makes sense since protocol cannot enforce properties to be stored
or computed
.
Is this possible to accomplish without introducing class inheritance
?
In other words, Can I observe the change of a property inside protocol extension?