SolvedAlamofire Extra argument 'method' in call

This line doesn't work on 4.0.0:

Alamofire.request("", method: .post, parameters: [], encoding: JSONEncoding.default)

I get "Extra argument 'method' in call" error.
I'm using XCode8 GM and your latest version.

23 Answers

✔️Accepted Answer

I'm getting the same issue, with the same error message ("Extra argument 'method' in call"), with correct parameters: syntax. The exact same argument structure worked before the latest project update. Are you sure this shouldn't be noted as a bug?

Alamofire.request("", method: .post, parameters: [:], encoding: JSONEncoding.default)

Other Answers:

@otherbuns Any time one argument is of the wrong type, the Swift interpreter here believes that you're wrongly using request(urlRequest:URLRequestConvertible) and therefore believes there's an extra method: argument.
What you should have done is read the release notes. Because one of the very last-minute and very nice additions to 4.0.0 is the ParameterEncoding protocol. More info here #1465 and here and mostly here Basically, you have to write your own struct conforming to ParameterEncoding with a function returning the encoded parameters.
EDIT: Oh well, I'm too slow to type 😅, already closed!

First of all : don't post this here, post it on Stack Overflow and tag it with Alamofire (I'm also monitoring those so you'd get the same answer but others could see it). As stated in the README, Github is for bugs and this isn't one.
Anyhow : parameters is of type Parameters? aka [String : Any]? and therefore giving it [] aka an empty Array is wrong (I'll admit that the error message is very misleading). You can write parameters: [:] (empty Dictionary), write nil or leave the whole parameters part out.

Okay, I find a interesting problem: ( I use swift4 and Alamofire4.7)
Alamofire.request(Constraint.PIC_STAR_URL, method: .post, parameters: params, encoding:.httpBody, headers:nil) will touch the error
Alamofire.request(Constraint.PIC_STAR_URL, method: .post, parameters: params, encoding: URLEncoding.httpBody, headers:nil) will touch no error
So, don't use the abbreviation of swift.

@thebluepotato Thanks for clarifying when to use Stackoverflow and when to use GitHub.

Turns out my original error was that I was trying to pass a URLRequest and not a URLConvertible. While reproducing I ended up with the string i presented when creating this topic which only led to more confusion. But now it works for me. Thank you.

More Issues: