I updated from Swift 3 to 4, and i am using RxSwift, When updated i came across an error "Extra argument in call" as it expects now of type element. I tried creating tuple of (response, data) but still gives me an error as shown.
public static func deleteCrush(receiver: String, receiver_type: ProviderType) -> Observable<(HTTPURLResponse, NSArray)> {
/*
Delete crush identified by `id`
*/
let parameters: Parameters = [
"receiver": receiver,
"receiver_type": receiver_type.rawValue
]
print("deleteCrush paramreters: \(parameters)")
return Observable.create({ (observer) -> Disposable in
Alamofire.request(Router.deleteCrush(parameters: parameters))
.rx
.responseJSON()
.debug()
.subscribe(onNext: { (response, json) in
print("deleteCrush response code: ", response.statusCode)
if let data = json as? NSArray {
observer.on(.next(response, data))
observer.on(.completed)
}
}, onError: { (error) in
print("deleteCrush error: ", error)
observer.on(.error(error))
}, onCompleted: nil, onDisposed: nil)
})
}
Error: Extra argument in call.
After trying to fix:
var tuple = (response, json)
if let data = json as? NSArray {
observer.on(.next(tuple))
observer.on(.completed)
}
Error:
Event<(HTTPURLResponse, NSDictionary)>' produces result of type 'Event', but context expects 'Event<(HTTPURLResponse, NSDictionary)>
Swift is probably having a hard time figuring out the type of the of the data you are sending in
.next
. Sometimes this happens and the compiler provides a completely useless error messageCheck your function definition. Specifically the return type. The observer you're returning may not be of the same type you are sending to your observers.
It just seems like you are not passing correct data type to your events.
Either simply wrap your tuple properly,
Or then use proper tuple type for your Element type,
Note that you are setting tuple as
tuple = (response, json)
which is not correct according to your method return type.