Contextual type for closure argument list expects 1 argument, but 4 were specified

前端 未结 2 1620
忘掉有多难
忘掉有多难 2020-12-10 12:47

I upgraded to Xcode 7 and I am using Alamofire to manage API calls and I am getting this error:

\'Contextual type for closure argument list expects 1 argument, but 4

相关标签:
2条回答
  • 2020-12-10 13:03

    The closure takes a single parameter of type Response<AnyObject, NSError> so your code should look more like this.

    Alamofire.request(.POST, urlString, parameters: parameters).responseJSON { response in
        let json = JSON(response.data!)
        let token = json["token"].string
        response(token: token)
    }
    
    0 讨论(0)
  • 2020-12-10 13:08

    Thanks for the help, this was my first time asking here and it was helpful and encouraging. Final code looks like this:

        static func loginWithEmail(email: String, password: String, func_response: (token: String?) -> ()) {
        let urlString = baseURL + ResourcePath.login.description
        let parameters = [
            "email": email,
            "password": password
        ]
        Alamofire.request(.POST, urlString, parameters: parameters).responseJSON { response in
            if response.result.isSuccess {
                let json = JSON(response.result.value!)
                let token = json["token"].string
                func_response(token: token)
            }
        }
    
    0 讨论(0)
提交回复
热议问题