maytime
maytime

Reputation: 121

How to create Timer on RxSwift to call the method every 10 seconds?

I want to create a Timer with RxSwift to call my method every 10 seconds, but l don't know how to make it the best way.

If you have any ideas, please, share!

Upvotes: 3

Views: 1565

Answers (2)

Daniel T.
Daniel T.

Reputation: 33979

There's no need for any extra libraries. The operator already exists in RxSwift.

Observable<Int>.interval(.seconds(10), scheduler: MainScheduler.instance)
    .subscribe(onNext: { _ in
        myMethod()
    })
    .disposed(by: disposeBag)

Upvotes: 3

Shehata Gamal
Shehata Gamal

Reputation: 100549

You can try this pod RxTimer

NSTimer.rx.timer(10)
  .subscribeNext { _ in
   print("timer triggered")
 }
 .addDisposableTo(disposeBag)

Upvotes: 1

Related Questions