Skip to content

Instantly share code, notes, and snippets.

@ncreated
Created August 11, 2017 16:43
Show Gist options
  • Save ncreated/162aaa28a97b5a842593c7c832a0c759 to your computer and use it in GitHub Desktop.
Save ncreated/162aaa28a97b5a842593c7c832a0c759 to your computer and use it in GitHub Desktop.
Medium blogpost snippet
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