RxSwift'额外参数' onError'迁移到Swift 4之后

时间:2018-04-19 16:51:44

标签: ios swift xcode rx-swift

试图找出原因,因为我尝试删除整个onError块,导致onCompleted块出错。

public static func register(phone_number: String, password: String) ->  Observable<(HTTPURLResponse, NSDictionary)> {
    /*
     Registers a user using their phone number and password

     */
    let parameters: Parameters = ["phone_number": phone_number, "password": password]
    return Observable.create({ (observer) -> Disposable in
        Alamofire.request(Router.register(parameters: parameters))
            .rx
            .responseJSON()
            .subscribe(onNext: { (response, json) in
                if let data = json as? NSDictionary {
                    if let returned_phone_number = data["phone_number"] as? String
                    {
                        if returned_phone_number == phone_number {
                            print("success")
                        } else {
                            print(returned_phone_number)
                        }

                    }

                     observer.on(.next(response, data))
                }
            }, onError: { (error) in \\ error here 'extra argument "onError" calls'
                observer.on(.error(error))
            }, onCompleted: { (response)  in
                observer.on(.completed)
            }, onDisposed: nil)
    })

}

1 个答案:

答案 0 :(得分:1)

问题在于onCompleted关闭。它必须没有任何参数,而在您的代码中它有一个(response)。您可以将其更改为

onCompleted: {
    observer.on(.completed)
}