I'm trying to reproduce a simple timer with RxSwift.
I have a pause/play button
only that works for pause and resume.
gameTimer = Observable<NSInteger>.interval(1, scheduler: MainScheduler.instance)
.subscribeNext({ sec -> Void in
print("\(sec) s")
}).addDisposableTo(disposeBag!)
pauseResumeButton.rx_tap
.map{ !self.isRunning.value }
.startWith(true)
.bindTo( isRunning )
.addDisposableTo(disposeBag!)
isRunning
is an Variable<Bool
> obviously.
I can stop the timer settings disposeBag = nil
but I cannot pause it....itried to filter events but the count obviously continues to grow...
Can anyone help me? Thanks!
A little trick:
Result: