title: Attempt to present <UIAlertController> on whose view is not in the window hierarchy
body: <p>I've been trying to present a UIAlertController when user entered wrong password for their account, the UIAlertController is located in one separate file inside a Model group which I extend the UIViewController class to add this alert functionality to it. I also has another file inside my model group namely LogIn which I wrote all the logic behind the login process so that I can call it to my LogInVC. However, I got an error of "Attempt to present  on whose view is not in the window hierarchy!" whenever the function get call inside my LogInVC. I'm trying to make my project in MVC and I know what caused this error but I just don't know how to fix it. May anyone tell me how to fix this problem?</p>
  
  <p><strong>Alert</strong></p>
  
  <pre><code>import Foundation
  import UIKit
  
  extension UIViewController {
  
      //MARK: - Not Enough Information Alert
      func notEnoughInfo(title: String, message: String) {
          let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
          let OKAction = UIAlertAction(title: "OK", style: .default, handler: nil)
          alertController.addAction(OKAction)
          self.present(alertController, animated: true, completion: nil)
      }
  
      //MARK: - Incorrect Username and Password
      func wrongInfo(title: String, message: String) {
          let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
          let OKAction = UIAlertAction(title: "Try again", style: .default, handler: nil)
          alertController.addAction(OKAction)
          self.present(alertController, animated: true, completion: nil)
      }
  
  
  </code></pre>
  
  <p><strong>LogIn</strong></p>
  
  <pre><code>import Foundation
  import Firebase
  
  class LogIn: UIViewController{
  
      let db = Firestore.firestore()
  
      //MARK: - userValidation()
      func userValidation(Username:String, Password:String){
  
          db.collection("users").getDocuments() { (querySnapshot, err) in
              if let err = err {
                  print("Error getting documents: \(err)")
              } else {
                  if let snapShotDocument = querySnapshot?.documents {
                      for doc in snapShotDocument {
                          let data = doc.data()
                              if let username = data[C.username] as? String, let password = data[C.password] as? String {
                                  if Username == username, Password == password {
                                      print("Log in Successfully")
                                  }
                                  else {
                                      self.wrongInfo(title: "Incorrect password", message: "Try again please")
                                  }
                              }
                      }
                  }
              }
          }
      }
  }
  
  </code></pre>
  
  <p><strong>LogInVC</strong></p>
  
  <pre><code>import UIKit
  import Firebase
  
  class LogInVC: UIViewController {
  
  
      @IBOutlet weak var emailTextField: UITextField!
      @IBOutlet weak var passwordTextField: UITextField!
      @IBOutlet weak var logInBtn: UIButton!
      let db = Firestore.firestore()
      let logIn = LogIn()
  
      override func viewDidLoad() {
          super.viewDidLoad()
          //logInBtn.layer.cornerRadius = logInBtn.frame.height/5
      }
  
      @IBAction func logInBtn(_ sender: UIButton) {
          if let username = emailTextField.text, let password = passwordTextField.text{
              if username.isEmpty || password.isEmpty{
                  notEnoughInfo(title: "Not enough information", message: "Please fill in all the necessary information.")
              }else{
                  logIn.userValidation(Username: username, Password: password) //here is where problem occured
                  //move to another viewcontroller
              }
          }
      }
  
      @IBAction func signUpBtn(_ sender: UIButton) {
          let push = storyboard?.instantiateViewController(withIdentifier: C.signUpVC) as! SignUpVC
          push.modalPresentationStyle = .fullScreen
          present(push, animated: true, completion: nil)
      }
  
  } //ends of class
  </code></pre>