I know there are tons of posts on the internet about this, I also know what this error message means, I have encountered it at least 50 times. Although I have tried for about 1 hour and I don't know why I am getting this error on this code:
usernameSignUp?.setPadding()
emailSignUp?.setPadding()
passwordSignUp?.setPadding()
usernameSignUp?.setBottomBorder()
emailSignUp?.setBottomBorder()
passwordSignUp?.setBottomBorder()
emailSignIn?.setPadding()
emailSignIn?.setBottomBorder()
passwordSignIn?.setPadding()
passwordSignIn?.setBottomBorder()
signUpButton?.layer.cornerRadius = 4
}
func validateFields() -> String? {
if usernameSignUp.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" ||
emailSignUp.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" ||
passwordSignUp.text?.trimmingCharacters(in: .whitespacesAndNewlines) == ""{
return "Please fill in all fields"
}
let cleanedPassword = passwordSignUp.text!.trimmingCharacters(in: .whitespacesAndNewlines)
if isPasswordValid(cleanedPassword) == false {
return "8 characters or more"
}
return nil
}
@IBAction func signUpTapped(_ sender: Any) {
let error = validateFields()
if error != nil {
showError(error!)
}
else {
let userName = usernameSignUp.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let email = emailSignUp.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let password = passwordSignUp.text!.trimmingCharacters(in: .whitespacesAndNewlines)
Auth.auth().createUser(withEmail: email, password: password) { (result, error) in
if error != nil {
self.showError("Invalid email")
}
else {
let db = Firestore.firestore()
db.collection("users").addDocument(data: ["username": userName, "uid": result!.user.uid]) { (error) in
if error != nil {
self.showError("Username could not be created")
}
}
self.transitionToHome()
}
}
}
}
func isPasswordValid(_ password : String) -> Bool {
let passwordTest = NSPredicate(format: "SELF MATCHES %@", ".{8,}")
return passwordTest.evaluate(with: password)
}
func showError(_ message:String) {
errorLabel.text = message
errorLabel.alpha = 1
}
func transitionToHome() {
let homeViewController = storyboard?.instantiateViewController(identifier: Constants.Storyboard.homeViewController) as? ViewController
view.window?.rootViewController = homeViewController
view.window?.makeKeyAndVisible()
}
@IBAction func emailLoginTapped(_ sender: Any) {
}
@IBAction func loginTapped(_ sender: Any) {
if let emailsignin = emailSignIn.text?.trimmingCharacters(in: .whitespacesAndNewlines),
let passwordsignin = passwordSignIn.text?.trimmingCharacters(in: .whitespacesAndNewlines) {
Auth.auth().signIn(withEmail: emailsignin, password: passwordsignin) { (result, error) in
if error != nil {
self.errorLabel3.text = error!.localizedDescription
self.errorLabel3.alpha = 1
}
else {
self.transitionToHome()
}
}
}
}
}
It is happening in the first two lines of code. If anyone could help it would be greatly appreciated.