Hews
Hews

Reputation: 581

Extra argument in call Alamofire Swift

I've been trying to resolve this error when I call Alamofire by fixing parameter types, changing the response-type from responseString to responseJSON and force-unwrapping variables. I've checked out the following answers and haven't had any luck:

Alamofire, Extra argument 'method' in call

Extra argument 'method' in call of Alamofire

Swift - Extra Argument in call

Swift 3.0, Alamofire 4.0 Extra argument 'method' in call

Here's my code:

 func checkServerForLogin(email: String, password: String) {

    let parameters = [
        "email": email,
        "password": password
        ] as [String : Any]

    Alamofire.request(URL_CHECK_LOGIN, method: .post, parameters: parameters).responseString { (response) in

        if response.result.error == nil {

            guard let data = response.data else {
                return
            }
            do {
                print("LOGIN_RESULT")
                print(response)

            } catch {
                print("ERROR: \(error)")
            }
        } else {
            debugPrint(response.result.error as Any)
        }
    }
}

Then I call it...

AuthService.instance.checkServerForLogin(email: email_input, password: password_input) { response, error in

            if ((response) != nil){

            }
        }

I keep receiving Extra argument 'password' in call. Any help in resolving this would be greatly appreciated.

Upvotes: 0

Views: 500

Answers (1)

Jigar
Jigar

Reputation: 1821

you have create simple method.you need to create completion block parameter

try this code

  class func checkServerForLogin(_ url:String,email: String, password: String,success:@escaping (JSON) -> Void, failure:@escaping (Error) -> Void) {

            let parameters = [
                "email": email,
                "password": password
                ] as [String : Any]

            Alamofire.request(url, method: .post, parameters: parameters).responseString { (response) in

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

AuthService.checkServerForLogin(URL_CHECK_LOGIN, email: email_input, password: password_input, success: { (responseObject) in
            print(responseObject)
        }) { (error) in
            print(error.localizedDescription)
        }

Upvotes: 1

Related Questions