Swift 4 "Extra Argument in Call" Rxswift

RxSwift: 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)

Swift 4 Extra argument in call Rxswift

It just seems like you are not passing correct data type to your events.

Either simply wrap your tuple properly,

observer.on(.next((response, data)))

Or then use proper tuple type for your Element type,

if let data = json as? NSArray {
var tuple = (response, data)

observer.on(.next(tuple))
observer.on(.completed)
}

Note that you are setting tuple as tuple = (response, json) which is not correct according to your method return type.

RxCocoa extra argument in call

Thanks to Philip Laine answer above: https://stackoverflow.com/a/36536320/2126233

That helped me see that I was making a mistake in regards to what I was observing. It helped me to see the problem I was having in my code.

If you just want to bind to a normal tableViewCell then you need to use tableView.rx_itemsWithCellFactory:

currentQuestion.asObservable()
.bindTo(tableView.rx_itemsWithCellFactory) {(tableView, row, item) in
let cell = UITableViewCell()
cell.textLabel?.text = item.distance

return cell

}.addDisposableTo(disposeBag)

If you are using a custom cell then you can use tableView.rx_itemsWithCellIdentifier("ChoiceCell", cellType: ChoiceCell.self). Here is an example:

 currentQuestion
.asObservable()
.filter { $0 != nil }
.map { $0!.choices }
.bindTo(tableView.rx_itemsWithCellIdentifier("ChoiceCell", cellType: ChoiceCell.self)) { (row, element, cell) in
cell.choiceModel = element
}
.addDisposableTo(disposeBag)

For me I was still getting this same error unless I had a property inside the tableView cell that matched the element that was coming out of the array I was binding the tableView to.

So if you have an array of [Taxis] like so then inside the tableViewCell I required a variable that stored a Taxis. Then I was able to compile my project.

So in ChoiceCell I have a var like so:

var taxi: Taxi? {
didSet {
layoutCell()
}

}

I hope this helps anyone else having issues binding a tableViewCell to an array.

Extra argument 'onError' in call using RXSwift Single Trait

Swift complier sometimes is very laggy. Especially when it comes to Rx. The problem is with this line

self.paymentAuthorizationFinishedWithError.onNext(APIResponseError.paymentAlreadyInProgress)

you forgot to add ? since you're using weak reference:
self?.paymentAuthorizationFinishedWithError.onNext(APIResponseError.paymentAlreadyInProgress)

Extra argument In Call When Using Searchbar

You are mixing up NSPredicate and filter syntax as well as NSSortDescriptor and sorted syntax. This cannot work.

Assuming todoItems is an array of a custom struct or class the native Swift way is

todoItems = todoItems.filter{ $0.title.range(of: searchBar.text!, options: [.caseInsensitive, .diacriticInsensitive]) != nil}
.sorted{ $0.dateCreated < $1.dateCreated}

Note: Consider that you are going to overwrite the array containing all items with the filtered array...

RxSwift: Extra argument 'onError' when subscribing on an ObservableString

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")})

Swift - Extra Argument in call

In some cases, "Extra argument in call" is given even if the call looks right, if the types of the arguments don't match that of the function declaration. From your question, it looks like you're trying to call an instance method as a class method, which I've found to be one of those cases. For example, this code gives the exact same error:

class Foo {

func name(a:Int, b: Int) -> String {
return ""
}
}

class Bar : Foo {
init() {
super.init()
Foo.name(1, b: 2)
}
}

You can solve this in your code by changing your declaration of setCity to be class func setCity(...) (mentioned in the comments); this will allow the ViewController.setCity call to work as expected, but I'm guessing that you want setCity to be an instance method since it appears to modify instance state. You probably want to get an instance to your ViewController class and use that to call the setCity method. Illustrated using the code example above, we can change Bar as such:

class Bar : Foo {    
init() {
super.init()
let foo = Foo()
foo.name(1, b: 2)
}
}

Voila, no more error.



Related Topics



Leave a reply



Submit