Sometimes it happens that you need to bind to several optional binders or to an optional method (for example, when using weak
). To do this, we can resort to large constructs with guard
, if
, weak capturing and others.
weak var someController: SomeController?
func bind() {
guard let binder = someController?.someView.rx.someBinder else { /*...*/ }
someObservable.bind(to: binder).disposed(by: bag)
}
The guard
construction looks a bit messy and it would be great to remove it (and put inside called function).
weak var someController: SomeController?
func bind() {
someObservable.bind(to: someController?.someView.rx.someBinder).disposed(by: bag)
}
It may seem that not so much changes and that the code is getting longer, but after a while you will realize that you saved a lot of time and space, and were able to write cleaner and more functional code (because optionals were created for this) ;)
You could install package via CocoaPods:
Add this line to your Podfile:
pod 'RxOptionals', :git => 'https://github.com/danyaffff/RxOptionals'
You could install package via Swift Package manager:
link |
Stars: 3 |
Last commit: 2 years ago |
Tests added
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics