I'm trying to toggle a Observable
I tried to use flatMap, but that either doesn't work or i'm using it incorrectly.
boolValue.flatMap { value -> value in
return !value
}
Any idea?
Hi @coryoso
Well, I think your rx_tap should be reflection of your viewModel behavior
Kind of
let flag: Variable<Bool>
button.rx_tap.map{ !flag.value }.bindTo(flag).addDisposable(disposeBag)
So in this case you will bind your UI triggers to viewModel
and then bind viewModel back to UI
Hi guys,
there is also a scan operator, so something like:
button.rx_tap
.scan(false) { state, _ in
!state
}
.startWith(false)
... should work.
You can also take a look at calculator example in RxExample app for further details.
Most helpful comment
Hi guys,
there is also a
scanoperator, so something like:... should work.
You can also take a look at calculator example in
RxExampleapp for further details.