Created
August 11, 2017 16:43
-
-
Save ncreated/162aaa28a97b5a842593c7c832a0c759 to your computer and use it in GitHub Desktop.
Medium blogpost snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func setUp(settingSwitch: UISwitch, with toggle: Toggle) { | |
let (value, isBusy) = toggle.manage(change: settingSwitch.rx.isOn.changed.asObservable()) | |
let initialValue = value | |
.filter { $0.isInitial } | |
.map { $0.value } | |
.flatMap { $0.map(Driver.just) ?? Driver.empty() } // .unwrap() if using `RxSwiftExt` | |
let fallbackValue = value | |
.filter { $0.isFallback } | |
.map { $0.value } | |
.flatMap { $0.map(Driver.just) ?? Driver.empty() } // .unwrap() if using `RxSwiftExt` | |
let switchValue = Driver.merge(initialValue, fallbackValue) | |
switchValue | |
.drive(settingSwitch.rx.isOn) | |
.disposed(by: disposeBag) | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment