Checking for required text fields for login I wrote this script and it's working quite well however I think there's too much if else statements on it. How could I change them for a switch statement?

@IBAction func sendLoginParameters(_ sender: UIButton) {

    if correoTextField.text?.isEmpty == true &amp;&amp; contrasenaTextField.text?.isEmpty == true {
        let alertMessage = UIAlertController(title: "Datos requeridos", message: "Favor de llenar todos los datos requeridos (CORREO Y CONTRASEÑA) antes de continuar", preferredStyle: .alert)
        alertMessage.addAction(UIAlertAction(title: "Aceptar", style: .default, handler: nil))
        self.present(alertMessage, animated: true, completion: nil)
        return

    } else if correoTextField.text?.isEmpty == true  {

        let alertMessage = UIAlertController(title: "Datos requeridos", message: "Favor de llenar todos los datos requeridos (CORREO) antes de continuar", preferredStyle: .alert)
        alertMessage.addAction(UIAlertAction(title: "Aceptar", style: .default, handler: nil))
        self.present(alertMessage, animated: true, completion: nil)
        return

    } else if contrasenaTextField.text?.isEmpty == true {

        let alertMessage = UIAlertController(title: "Datos requeridos", message: "Favor de llenar todos los datos requeridos (CONTRASEÑA) antes de continuar", preferredStyle: .alert)
        alertMessage.addAction(UIAlertAction(title: "Aceptar", style: .default, handler: nil))
        self.present(alertMessage, animated: true, completion: nil)
        return
} else {
...
In my opinion the issue here is not the repetition of if else but the repetition of similar alert message code.

For example, you could continue using if else but without these repetitions:

guard let correoText = correoTextField.text, let contrasenaText = contrasenaTextField.text else {
    fatalError("The outlets are not properly connected")
}
var msg: String? = nil
if correoText.isEmpty &amp;&amp; contrasenaText.isEmpty {
    msg = "CORREO Y CONTRASEÑA"
} else if correoText.isEmpty {
    msg = "CORREO"
} else if contrasenaText.isEmpty {
    msg = "CONTRASEÑA"
}
if let msg = msg {
    let alertMessage = UIAlertController(title: "Datos requeridos", message: "Favor de llenar todos los datos requeridos (\(msg)) antes de continuar", preferredStyle: .alert)
    alertMessage.addAction(UIAlertAction(title: "Aceptar", style: .default, handler: nil))
    self.present(alertMessage, animated: true, completion: nil)
}


But if you want to use switch, you can switch on a tuple representing the two booleans:

guard let correoText = correoTextField.text, let contrasenaText = contrasenaTextField.text else {
    fatalError("The outlets are not properly connected")
}
let msg: String?
switch (correoText.isEmpty, contrasenaText.isEmpty)  {
case (true, true):
    msg = "CORREO Y CONTRASEÑA"
case (true, false):
    msg = "CORREO"
case (false, true):
    msg = "CONTRASEÑA"
default:
    msg = nil
    // implement additional behavior, or add more cases
}
let alertMessage = UIAlertController(title: "Datos requeridos", message: "Favor de llenar todos los datos requeridos (\(msg)) antes de continuar", preferredStyle: .alert)
alertMessage.addAction(UIAlertAction(title: "Aceptar", style: .default, handler: nil))
self.present(alertMessage, animated: true, completion: nil)