Search code examples
swiftgetalamofire

Alamofire GET request with parameters, -> "extra argument in call"


I am trying to make a GET request using Alamofire with parameters to a backend written in python.

I tried several ways of doing this with no success and i read somewhere that i should remove parameters in order to get a clean GET request and it worked.

I still need to use parameters so i saw this post: Get JSON result with GET request and parameters with Alamofire

Trying the solution there, Xcode gives me an instant error: extra argument in call

This is how it looks like when i get my error:

 Alamofire.request(.GET, urlString, parameters: ["test":"te"]).responseJSON {
            (responseObject) -> Void in

            print(responseObject)

            if responseObject.result.isSuccess {
                let resJson = JSON(responseObject.result.value!)
                success(resJson)
            }
            if responseObject.result.isFailure {
                let error: NSError = responseObject.result.error!
                failure(error)
            }
        }

Solution

  • You just have wrong order of parameters and for parameter method you forgot to write parameter name.

    Change this

    Alamofire.request(.GET, urlString, parameters: ["test":"te"]).responseJSON {
    

    to this

    Alamofire.request(urlString, method: .get, parameters: ["test":"te"]).responseJSON {
    

    You can anytime check function parameters when you jump to its definition. Just hold Command and click to function and select Jump to Definition

    enter image description here

    now you can see request method parameters

    enter image description here