我想让人们登录到特定域,但是它总是显示错误。
无法将“字符串”类型的值转换为预期的参数类型“整数”。
我该如何处理?
import UIKit
import FirebaseAuth
class ViewController: UIViewController {
@IBOutlet var emailTextField: UITextField!
@IBOutlet var passwordTextField: UITextField!
@IBAction func signUp(_ sender: Any) {
Auth.auth().createUser(withEmail: emailTextField.text!, password: passwordTextField.text!) { (result, error) in
if error != nil{
print(error)
}else{
self.performSegue(withIdentifier: "createdUser", sender: self)
}
}
}
@IBAction func signIn(_ sender: Any) {
Auth.auth().signIn(withEmail: emailTextField.text!, password: passwordTextField.text!) { (result, error) in
if error != nil{
print(error)
}else{
var hi = self.emailTextField.text
if hi?.suffix("@hkugac.edu.hk"){ //error here
self.performSegue(withIdentifier: "logged", sender: self)
}
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}
答案 0 :(得分:0)
尝试使用hasSuffix方法。 https://developer.apple.com/documentation/swift/string/1541149-hassuffix
var hi = self.emailTextField.text
if let mail = hi, mail.haSuffix("@hkugac.edu.hk")
{
self.performSegue(withIdentifier: "logged", sender: self)
}
else
{
// Dome some error handling here.
}
此外,我认为最好在调用signIn函数之前先检查邮件 。