问题
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