I have the following code:
let fetcher = DiagnosticFetcher(commandSender: sender)
fetcher.fetch()
.observeOn(MainScheduler.instance)
.subscribe(
onNext: { self.store.save(content: $0) },
onError: { self.view.showError("Error") },
onCompleted: { log.verbose("Diagnostic fetched") })
It does not compile: Extra argument 'onError' in call
. I get the same error if I use onSuccess
or onDoesNotExistButShowTheBug
instead of onNext
.
The fetch()
method returns a Observable<String>
(whose last operator is a reduce
). It seems that the subscribe()
call expects only one lambda:
fetcher.fetch()
.observeOn(MainScheduler.instance)
.subscribe(onNext: { self.store.save(content: $0) })
Results in: Extraneous argument label 'onNext:' in call
. And:
fetcher.fetch()
.observeOn(MainScheduler.instance)
.subscribe({ self.store.save(content: $0) })
compiles fine.
I feel like I get the wrong subscribe()
implementation. I want that one:
public func subscribe(onNext: ((ElementType) -> Void)? = nil,
onError: ((Swift.Error) -> Void)? = nil,
onCompleted: (() -> Void)? = nil) -> Disposable {
but obviously, the compiler doesn't. I'm using XCode 9.2 with Swift 4 and RxSwift 4.1.1.
I have other parts in my app that use the onNext:onError:
on an observable where it works. I can't put my finger on what is different for this call.
Any thought on how I can identify the root of the issue?
I got it to compile by specifying the first parameter in the onError
lambda:
fetcher.fetch()
.observeOn(MainScheduler.instance)
.subscribe(
onNext: { self.store.save(content: $0) },
onError: { _ in self.view.showError("Error")})
Adding my contribution.
I had the same issue but, in my case:
recordHeader.albumArray.asObservable()
.subscribe(onNext: { [weak self] value in
self?.populateView(recordHeader: value)
})
.disposed(by: disposeBag)
The value type of the function "populateView" didn't match to value type of value
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