December 2018
Intermediate to advanced
414 pages
10h 19m
English
UIControls, like UISwitch, UITextView, and UISlider, emit events when their underlying values have changed. On the other hand, we have the Observable object that also emits events when the underlying value changes. Using what we have learned about protocol-oriented programming, we'll extend UIControls, in order to be able to bind them.
First, let's look at the Bindable protocol:
protocol Bindable: AnyObject { associatedtype BoundType var boundValue: BoundType { get set }}
We'll use the boundValue member as a proxy. The getters should always return the current value of the component, and the setter should update the value:
extension Bindable where Self: NSObjectProtocol { private var observable: Observable<BoundType>? ...Read now
Unlock full access