0

Xcode forced me to update some old swift 2.3 syntax to 3.0. Alamofire is 4.0.1. When trying to build a project it fails with error for extra argument in call.

Alamofire.request(url, .GET, parameters: ["part":"snippet,contentDetails", "key": API_KEY,"maxResults":50, "channelId":channelId], encoding: ParameterEncoding.URL, headers: nil).responseJSON { (response) in

How do i fix this issue. It shows up in over 6 files in project. Almost identical error.

vadian
  • 274,689
  • 30
  • 353
  • 361
vinny
  • 529
  • 4
  • 7
  • 16
  • Possible duplicate of [Alamofire extra argument 'method' in call](http://stackoverflow.com/questions/40181731/alamofire-extra-argument-method-in-call) – vadian Nov 13 '16 at 05:54
  • The answer on that question, didn't work for me. – vinny Nov 13 '16 at 05:57

2 Answers2

2

Do the call like below

Alamofire.request(url, 
                  parameters: ["part":"snippet,contentDetails", "key": API_KEY,"maxResults":50, "channelId":channelId], 
                  encoding: URLEncoding.default)
         .responseJSON { (response) in
}

I hope it will work... For more info, you can check out the link https://github.com/Alamofire/Alamofire#get-request-with-url-encoded-parameters

haider_kazal
  • 3,448
  • 2
  • 20
  • 42
2

After Migration Swift 2.3 to Swift 3 you need to also change in to the Alamofire Library method need to call like this

Swift 3

      let parameters = ["action":"cms", "id":"1"]
            
      Alamofire.request("Your webAPI link here", method: .get, parameters: parameters)
                .responseJSON { response in
                    
                    print("Success: \(response.result.isSuccess)")
                    print("Response String: \(response.result.value)")
                    switch response.result {
                    case .success:
                        self.successGetTermsData(response.result.value! as AnyObject)
                    case .failure(let error):
                        self.failedGetData()
                        print(error)
                    }
            }

For better understanding you can also check this - Alamofire 4.0 Migration Guide

Community
  • 1
  • 1
Anand Nimje
  • 6,163
  • 4
  • 24
  • 43