Chaudhry Talha Chaudhry Talha - 1 year ago 130
iOS Question

Extra argument 'method' in call of Alamofire

I've searched for this issue and there are many answers available but none are solving. I've defined parameters as:

let parameters = [
"name": username,
"mobile": "",
"email": email,
"password": "",
"blood_donor": "0",
"registration_id": defaults.string(forKey: "FCMToken"),
"platform": platform,
"appID": "3"
]


And after that when I send the request:

Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding(), headers: headers).responseJSON { response in


So I get a warning on
parameters



Expression implicitly coerced from 'String?' to Any


and if I put
!
next to parameters I start getting this error:


Extra argument 'method' in call


The function in which I've written all fo this is:
func sendLoginCall(username: String, email: String, platform: String)
. I have tried replacing
URLEncoding()
to
JSONEncoding.default
it didn't work.

I'm calling this is method like this:

if let userName = data["name"], let email = data["email"] {
self.sendLoginCall(username: userName as! String, email: email as! String, platform: "fb")
}

Answer Source

Change parameters type to [String : Any] as follow:

let parameters = [
                "name": username,
                "mobile": "",
                "email": email,
                "password": "",
                "blood_donor": "0",
                "registration_id": defaults.string(forKey: "FCMToken"),
                "platform": platform,
                "appID": "3"
            ] as [String : Any]

Not necessary: Remove encoding: URLEncoding() from param arguments, it may work without encoding.

Here is discussion on same issue and resolution by Alamofire developer: https://github.com/Alamofire/Alamofire/issues?utf8=%E2%9C%93&q=extra%20argument

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download