Skip to content

Instantly share code, notes, and snippets.

@ncreated
Last active August 11, 2017 17:03
Show Gist options
  • Save ncreated/307ecefdbbf14e533da1837c0b2a6f81 to your computer and use it in GitHub Desktop.
Save ncreated/307ecefdbbf14e533da1837c0b2a6f81 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 fallbackValue = value
.filter { $0.isFallback }
.map { $0.value }
.flatMap { $0.map(Driver.just) ?? Driver.empty() } // .unwrap() if using `RxSwiftExt`
// ...
let shouldPlayShakeAnimation = fallbackValue
.map { _ in () }
shouldPlayShakeAnimation
.drive(onNext: { _ in
settingSwitch.shake()
})
.disposed(by: disposeBag)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment