I'm switching from RAC and want to have a repeated network request, returning different result types depending on the API of the request.
I want to use an interval, but I don't know how to match the return types.
var loop: Observable<Element> {
return Observable<Int>.interval(5.0, scheduler: MainScheduler.instance).map { _ in
// Do network request and return Observable<Element>
}
}
I need to invoke Observerable.interval with type Int - but return Observable. How would I do that?
Use flatMap:
var loop: Observable<Element> {
return Observable<Int>.interval(5.0, scheduler: MainScheduler.instance).flatMap { _ in
return networkRequest() // returns Observable<Element>
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With