0
 let email  = capgEmailTextField.text
 func isEmailValid(str :String) -> Bool {
      let emailRegEx = "[A-Z0-9a-z._%+-]+@[A-Za-z]+\\.[A-Za-z]{2,4}"
      let testMail = NSPredicate(format : "SELF MATCHES %@", emailRegEx)
      return testMail.evaluate(with : str)
            }
            
          
  if !isEmailValid(str: email!){
           
     print("Email is not valid")
                
     let alert = UIAlertController(title: "Note", message: "Email is not valid", preferredStyle: .alert)
    alert.addAction(UIAlertAction(title: "Okay", style: .cancel, handler: nil))
    present(alert, animated: true, completion: nil)
    }
  else if isEmailValid(str: email!){
     print("Emailvalid so m saving")
   do{
   //  AppDelegate.shared().saveContext()
       let alert = UIAlertController(title: "Note", message: "Details submitted", preferredStyle: .alert)
 alert.addAction(UIAlertAction(title: "OK", style: .cancel, handler: nil))
    present(alert, animated: true, completion: nil)
                    }

它进入 if 语句并检查条件,但仍然保存。不输入 else 语句。但是当保存上下文被评论时它被保存了所以我不知道它是如何被保存的

4

0 回答 0