I have following code in Swift 4 with RxSwift
worthReacting.flatMap{ (userSearch) in
translator.getTranslation(ofWord: userSearch)
}.subscribe(
onSuccess: {(dataModel) in
state.value = .translation(word: dataModel.definition,
translations: dataModel.translations)
},
onError: {(error) in
state.value = .networkError
},
onCompleted: {
state.value = .unknownWord
}).disposed(by: disposeBag)
worthReacting
has type of Observable<String>
translator.getTranslation
returns Maybe<DataModel>
I'm getting build error
Extra argument 'onError' in call
Maybe
flatmaped into Observable
produces Observable
. Observable
can not emit onSuccess
event, instead it will emit onNext
. Following code will work:
worthReacting.flatMap{ (userSearch) in
translator.getTranslation(ofWord: userSearch)
}.subscribe(
onNext: {(dataModel) in
self.state.value = .translation(word: dataModel.definition,
translations: dataModel.translations)
},
onError: {(error) in
self.state.value = .networkError
},
onCompleted: {
self.state.value = .unknownWord
}).disposed(by: disposeBag)
For those who get the OP's error, but have a different cause, check that you have not incidentally make one of your closures throwing
by not making your do-catch
clause exhaustive.
Also, take care that you don't use a single-statement closure (in this case you should explicitly return
).
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