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)
}
It enters the if statement and checks for the condition but saves anyways . Doesn't not enter else statement. But when save context was commented it got saved so I don't know how its getting saved