Set Validation in button click iOS

func validationTextfield() -> String
    {
        if(txtEmail.text? .isEmpty)!{
            return "Please enter email."
        }
        else if(txtPassword.text? .isEmpty)!{
            return "Please enter password."
        }
        return ""
    }

Button click method and call above function.

@IBAction func btnLogin_Click(_ sender: UIButton){
        let str = validationTextfield()
        if str == "" {
           //write your code.
        }else{
            displayAlertWithMessage(str)
        }
    }