After updating to the release version of RxSwift I'm having trouble converting my timer usage. I was using timer like this:
timerDisposable = timer(0, 0.1, MainScheduler.sharedInstance)
.subscribeNext { [weak self] _ in self?.updateCurrentPlayingTime() }
But now I'm trying to change it to:
timerDisposable = Observable.timer(0, period: 0.1, scheduler: MainScheduler.instance)
.subscribeNext { [weak self] _ in self?.updateCurrentPlayingTime() }
and I'm getting an error timer has no IntegerLiteralType and I'm having trouble tracking it down.
I also tried this:
let startTime = RxTimeInterval(0)
let intervalTime = RxTimeInterval(0.1)
Observable.timer(startTime, period: intervalTime, scheduler: MainScheduler.instance)
but no dice.
Hi @marlowcharite,
please use it this way
Observable<Int>.timer(startTime, period: intervalTime, scheduler: MainScheduler.instance)
Observable<Int64>.timer(startTime, period: intervalTime, scheduler: MainScheduler.instance)
....
@kzaher Really quick response, appreciate that. I'm curious though since I'm not especially interested in the actual time coming back because on that interval I'm calling a method that pulls a music player for its current time and storing it in a Variable type. So my question is I can ignore the returned value on subscribe next but is there a better way to handle this use case?
@marlowcharite You can just map to void:
extension ObservableType {
// Useful for mapping an Observable<Whatever> into an Observable<Void> to hide details.
public func mapToVoid() -> Observable<Void> {
return self.map { _ -> Void in
return ()
}
}
}
Most helpful comment
@marlowcharite You can just map to void: