Created
May 25, 2020 19:14
-
-
Save tobitech/a22365c151f72ba18587bcca2f3bba8e to your computer and use it in GitHub Desktop.
Count down timer with RxSwift
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
let timer = Observable<Int>.interval(.seconds(1), scheduler: MainScheduler.instance) | |
.take(60) | |
.startWith(0) | |
.share(replay: 1) | |
timer | |
.map { 60 - $0 } | |
.map { "\($0)" } | |
.bind(to: timerLabel.rx.text) | |
.disposed(by: disposeBag) | |
timer | |
.takeLast() | |
.map { _ in true } | |
.startWith(false) | |
.bind(to: timerLabel.rx.isHidden) | |
.disposed(by: disposeBag) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment