使用Xcode 9.2发送Alamofire POST请求遇“Extra argument method in call”错误求解决
Hey there! Let’s get that Alamofire POST request sorted out—this error is super common when parameter types don’t match what Alamofire expects. Here’s what’s going wrong in your code and how to fix it:
1. Incorrect Encoding Parameter
The first issue is with your encoding argument: you’re passing JSONEncoding (the type itself) instead of an instance of it. Alamofire expects a ParameterEncoding instance here, so you need to use JSONEncoding.default (or JSONEncoding() if you need custom options later).
2. Typos in Response Handling
You’ve got a couple of spelling mistakes in the response closure that’ll break things too:
response.results.errorshould beresponse.result.error(singularresult, not plural)response.resultd.erroris a typo—correct it toresponse.result.error
Corrected Code
Here’s your fixed request code, cleaned up for readability:
Alamofire.request(URL_REGISTER, method: .post, parameters: body, encoding: JSONEncoding.default, headers: header) .responseString { (response) in if response.result.error == nil { completion(true) } else { completion(false) debugPrint(response.result.error as Any) } }
Why This Fixes the Error
The "Extra argument 'method' in call" error pops up because the compiler can’t match your parameters to any valid request method signature. When you pass the wrong type for encoding, it throws off the method resolution entirely—making the compiler think you’ve added an extra argument where it doesn’t belong. Fixing the encoding type and typos aligns your code with Alamofire’s expected method signature, and the error should disappear.
内容的提问来源于stack exchange,提问作者Calongi

