当我调用Alamofire时,我一直在尝试通过修复参数类型,将响应类型从responseString
更改为responseJSON
并强制展开变量来解决此错误。我已经检查了以下答案,但没有任何运气:
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
这是我的代码:
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)
}
}
}
那我叫它...
AuthService.instance.checkServerForLogin(email: email_input, password: password_input) { response, error in
if ((response) != nil){
}
}
我一直收到Extra argument 'password' in call
。解决这个问题的任何帮助将不胜感激。
答案 0 :(得分:1)
您已经创建了简单的方法。您需要创建完成块参数
尝试此代码
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)
}