i have a question about ReactiveCocoa (v5) with Swift 3. In my project I have different services. For example the api or for saving or getting stuff from disk. Those services are returning SignalProducer. I have now something like a sequence of calling different services which are reliant on each other. Here the sequence:
- calling service to get key
- calling api with service by using key
- getting data form api (returns multiple models)
- save first model with first-model-service
- save second model with second-model-service
In my sequence I have to pass also data from the second service call down to the model saving.
keyService.get().flatMap(.latest) { (key) -> SignalProducer<[Data],Error> in
return self.dataService.get()(key: key)
}
.flatMap(.latest) { (data) -> SignalProducer<Bool, Error> in
return self.firstModelService.save(data["Model1"])
}
.flatMap(.latest) { (data) -> SignalProducer<Bool, Error> in
//how to get data here?
return self.secondModelService.save(data["Model2"])
}.startWithFailed({ e in
})
Furthermore is it possible that if one of the SignalProducer
along the sequence is sending an error that the complete sequence will stop and a callback is called with the error as the parameter. I don't know if startWithFailed
is the correct function here.
Does someone has a similar scenario like mine and can give me an example? I read through some tutorials but I can't figure it out.