Hey everybody!
I use Moya 10.0.0 and Moya Model Mapper.
I'll try to do soemthing like that:
private func getDataFromServer() -> Observable<DataModel> {
return loadIDFromDB().flatMapLatest { id_Data -> Observable<DataFromServer> in
let provider = MoyaProvider<CustomEndpoint>()
return provider.rx.request(.GetData(id_Data ))
.debug()
.mapJSON()
.asObservable()
}.map{ jsonData -> DataFromServer in
return self.mapData(jsonData)
}
}
func loadData() {
getDataFromServer().subscribe {
// DO SOMETHING
}.disposed(by:db)
}
The debug output states that it gets subscribed, but there is never a server call.
If I would just subscribe instead of flatmapLatest and then subscribe again inside the subscribe and store the data in a Variable it works. But this is no real solution for me.
Maybe I am getting something wrong with Rx? But usually this works for me.
Any ideas?
Kind regards!
Hey @bweickert,
I think you need to be keeping a reference to your MoyaProvider outside of the function body
Docs: https://github.com/Moya/Moya/blob/master/docs/Providers.md
Related: https://github.com/Moya/Moya/pull/1386
Awesome! Thank you very much @SD10! That was the issue.
Most helpful comment
Hey @bweickert,
I think you need to be keeping a reference to your MoyaProvider outside of the function body
Docs: https://github.com/Moya/Moya/blob/master/docs/Providers.md
Related: https://github.com/Moya/Moya/pull/1386