Alamofire Swift 3 - Extra Argument in Call Error

佐手、 提交于 2019-12-12 03:48:28

问题


Xcode forced me to update some old swift 2.3 syntax to 3.0. Alamofire is 4.0.1. When trying to build a project it fails with error for extra argument in call.

Alamofire.request(url, .GET, parameters: ["part":"snippet,contentDetails", "key": API_KEY,"maxResults":50, "channelId":channelId], encoding: ParameterEncoding.URL, headers: nil).responseJSON { (response) in

How do i fix this issue. It shows up in over 6 files in project. Almost identical error.


回答1:


Do the call like below

Alamofire.request(url, 
                  parameters: ["part":"snippet,contentDetails", "key": API_KEY,"maxResults":50, "channelId":channelId], 
                  encoding: URLEncoding.default)
         .responseJSON { (response) in
}

I hope it will work... For more info, you can check out the link https://github.com/Alamofire/Alamofire#get-request-with-url-encoded-parameters




回答2:


After Migration Swift 2.3 to Swift 3 you need to also change in to the Alamofire Library method need to call like this

Swift 3

      let parameters = ["action":"cms", "id":"1"]

      Alamofire.request("Your webAPI link here", method: .get, parameters: parameters)
                .responseJSON { response in

                    print("Success: \(response.result.isSuccess)")
                    print("Response String: \(response.result.value)")
                    switch response.result {
                    case .success:
                        self.successGetTermsData(response.result.value! as AnyObject)
                    case .failure(let error):
                        self.failedGetData()
                        print(error)
                    }
            }

For better understanding you can also check this - Alamofire 4.0 Migration Guide



来源:https://stackoverflow.com/questions/40570988/alamofire-swift-3-extra-argument-in-call-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!