Rxswift: Having trouble using Observable timer w/ release version

Created on 3 Jan 2016  路  3Comments  路  Source: ReactiveX/RxSwift

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.

Most helpful comment

@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 ()
        }
    }
}

All 3 comments

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 ()
        }
    }
}
Was this page helpful?
0 / 5 - 0 ratings