I need an observable property on certain view controllers in my application, I'm trying to standardize this through a protocol.
protocol MyProtocol: UIViewController {
dynamic var observeMe: Bool { get set }
}
But when trying to observe the property like so:
let viewController = UIViewController()
if let observableViewController = viewController as? MyProtocol {
observableViewController.observe(\.observeMe, options: [.old, .new], changeHandler: { object, change in
// Do something
})
}
Xcode throws the compiler error:
"Member 'observe' cannot be used on value of protocol type 'MyProtocol'; use a generic constraint instead"