Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

countdown timer by `RxSwift`

Tags:

swift

rx-swift

I need a thirty-second time counter with RxSwift. This is a duplicate question but there is no clear answer to the questions

like image 605
Behzad Moulodi Avatar asked Dec 08 '22 11:12

Behzad Moulodi


1 Answers

Better approach for existing answer.

let countDown = 15 // 15 seconds 
Observable<Int>.timer(.seconds(0), period: .seconds(1), scheduler: MainScheduler.instance)
        .take(countDown+1)
        .subscribe(onNext: { timePassed in
            let count = self.countDown - timePassed
            print(count)

        }, onCompleted: {
            print("count down complete")
        })
like image 157
SanRam Avatar answered Dec 24 '22 20:12

SanRam