Chaudhry Talha
Chaudhry Talha

Reputation: 7858

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")
                        }

Upvotes: 2

Views: 310

Answers (1)

Krunal
Krunal

Reputation: 79646

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

Upvotes: 2

Related Questions