how do I map this
func save() -> SignalProducer<Void, NetworkError>
to
var saveAction: Action<AnyObject, Bool, NoError>
i'm a bit confused with the syntax
service.save()
.observeOn(QueueScheduler.mainQueueScheduler)
.map<Bool>( _ in true) // how to map void to bool
.flatMapError {
error in
// how to map to a NoError?
}
also, what should be the best practice in using actions? should the NetworkError bubble up to the controller so it can display the error in a Popup dialog?
You ask 3 things, so let's go one by one:
Assuming you have a
foo: SignalProducer<Void, Error>:This is not intuitive, but you can make use of Swift's type inference and do something like this:
Your
func save() -> SignalProducer<Void, NetworkError>could then become:Eventually you have to convert the error into something readable. The Controller (assuming we are talking about the
UIViewController), could make use of a secondary entity to translate this error, into a string or a pair of strings (title + body). If you are using MVVM, the ViewModel, would that transformation.