There are many classes of UIKIt implemented in RxCocoa. UIButton’s touchUpInside click method is used in many scenarios, so RxSwift adds a tap method to directly subscribe to UIButton’s click method.
The implementation is also an extension to UIControl.
This procedure creates an Observable (AnonymousObservable) object and a ControlEvent object. The Observable is held as the source by the ControlEvent and returns the ControlEvent object.
Subscribe
(_ Observer: Observable (Observer) -> Disposable (); subscribe (Observable); The final call to AnonymousObservable’s _subscribeHandler, the following code block, implements the event binding via controlTarget.
{ [weak control = self.base] observer in MainScheduler.ensureRunningOnMainThread() guard let control = control else { observer.on(.completed) return Disposables.create() } let controlTarget = ControlTarget(control: control, controlEvents: controlEvents) { _ in observer.on(.next(())) }
return Disposables.create(with: controlTarget.dispose) }
Copy the code