user2636197
user2636197

Reputation: 4122

Alamofire v4 extra argument method in call error

Once I updated to alamofire version 4 I get the error: extra argument method in call

Alamofire.request("www.blabla", method: .put, parameters: parameters, headers: headers, encoding: .JSON)

I already changed it to use "method: .put" like above but I still get the error

Upvotes: 0

Views: 1725

Answers (4)

mevdev
mevdev

Reputation: 787

I broke mind into URLRequest and then just the Alamofire call. Nothing I found worked except breaking it up. I'm using Swift 3 and XCode 8.2.1 and I believe this is swift's sourceKit getting an object wrong.

this

    Alamofire.request(url:treeURL!, method: .get, parameters: [:], encoding: JSONEncoding.default, headers: ["Authorization" : app.getToken()])

became this:

    var request = URLRequest(url: treeURL!)
    request.httpMethod = "GET"
    request.allHTTPHeaderFields = ["Authorization" : app.getToken()]
    Alamofire.request(request as URLRequestConvertible)

Upvotes: 1

DerFlickschter
DerFlickschter

Reputation: 1059

I had this issue upgrading to Alamofire 4 and solved it by moving the headers argument and making it the last argument in the call. Also encoding: .JSON should be encoding: JSONEncoding.default.

Call should look like this:

Alamofire.request(url: myUrl, method: .put, parameters: myParams,
     encoding: JSONEncoding.default, headers: myHeaders)

Upvotes: 2

e.ozmen
e.ozmen

Reputation: 253

Alamofire.request( "http://....", method: .put , parameters: parameters, encoding:  JSONEncoding.default).responseJSON{
            response in
            if response.result.isSuccess {
                //some code
            }
        }

Upvotes: 0

midori
midori

Reputation: 450

What type is parameters? It has to be at least [:] - like:

Alamofire.request(url: myUrl, method: .put, parameters: [:], encoding: JSONEnconding.default, headers: myHeaders)

Upvotes: 2

Related Questions