// OTPViewController.swift
// FinalBookingApp
//
// Created by Makwin Santhosh K on 19/10/22.
//
import UIKit
import FirebaseAuth
import Firebase
import FirebaseCore
class OTPViewController: UIViewController {
@IBOutlet weak var OTPLabel: UILabel!
@IBOutlet weak var EnterOTPLabel: UILabel!
@IBOutlet weak var MailTextField : UITextField!
@IBOutlet weak var PasswordTextField: UITextField!
@IBOutlet weak var EnterOTPTextField: UITextField!
@IBOutlet weak var VerifyButton: UIButton!
@IBOutlet weak var ErrorLabel : UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
// check the data validate Things
func validateFields() -> String?{
if PasswordTextField.text?.trimmingCharacters(in: .whitespacesAndNewlines) == "" // // im getting error in this error saying "Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value"
{
return "Please enter the password without the BlankSpaces"
}
let cleanedPassword = PasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
if Helpers.isPasswordValid(cleanedPassword) == false{
//Password wasn't secure enough
return "Please make sure your password is at least 8 characters, contains a special character and a number."
}
return nil
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
@IBAction func ButtonTapped(_ sender: Any) {
let error = validateFields()
if error != nil {
// There's something wrong with the fields, show error message
showError(error!)
}
else {
let Email = MailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
let Password = PasswordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
//MARK: Create a User
Auth.auth().createUser(withEmail: Email, password: Password){(result,err) in
if err != nil {
// There was an error creating the user
self.showError("Error creating user")
}
else {
let db = Firestore.firestore()
db.collection("Users").addDocument(data: ["mail" : Email, "uid" : result!.user.uid])
}
}
self.TransistiontoHome()
}
}
func showError(_ message : String){
ErrorLabel.text = message
ErrorLabel.alpha = 1
}
func TransistiontoHome() {
}
}
Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value .... what im I doing wrong
Are you sure you connected properly PasswordTextField IBOutlet to the textField in storyboard ? Or may be the connection was damaged.
So disconnect the textField and reconnect.
Yes you are correct