Skip to content

Instantly share code, notes, and snippets.

@tobitech
Created May 25, 2020 19:14
Show Gist options
  • Save tobitech/a22365c151f72ba18587bcca2f3bba8e to your computer and use it in GitHub Desktop.
Save tobitech/a22365c151f72ba18587bcca2f3bba8e to your computer and use it in GitHub Desktop.
Count down timer with RxSwift
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