【发布时间】:2023-03-21 16:14:01
【问题描述】:
当我调用 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。任何解决此问题的帮助将不胜感激。
【问题讨论】:
-
checkServerForLogin()不是 Alamofire 中的功能,据我所知。 -
嘿,我做了一个单例类,AuthService,然后通过那里调用函数。不过谢谢:)
-
您的方法声明
checkServerForLogin(email: String, password: String)似乎只有两个参数,而在函数调用中,您使用了三个参数,即email、password和一个转义闭包参数 -
你的函数没有block参数,所以你有这个错误,它与Alamofire无关,只是你的函数