You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Xcode 9.2发送Alamofire POST请求遇“Extra argument method in call”错误求解决

Fixing "Extra argument 'method' in call" with Alamofire POST Requests in Xcode 9.2

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.error should be response.result.error (singular result, not plural)
  • response.resultd.error is a typo—correct it to response.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:25:00