swift - validando UITextField

Tengo estos puntos de venta en mi aplicación:

@IBOutlet var name1: UITextField!

@IBOutlet var name2: UITextField!

@IBOutlet var name3: UITextField!

@IBOutlet var name4: UITextField!

@IBOutlet var newButton: UIButton!

Lo que intenté hacer es lo siguiente:

Cada vez que el usuario escribe algo en uno de estos cuatro campos de texto o elimina algo, quiero verificar si algún campo de texto está vacío

Si algún campo de texto está vacío, el botón debe estar deshabilitado.

Si todos los campos de texto están configurados (no vacíos), el botón debería estar habilitado.

Mi código:

func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

    setButton()

    return true
}

func setButton() {

    let inputValid = checkInput()

    if inputValid {

        newButton.enabled = true

    } else {

        newButton.enabled = false

    }

}

func checkInput() -> Bool {

    let name1Value = name1.text
    let name2Value = name2.text
    let name3Value = name3.text
    let name4Value = name4.text

    if !name1Value.isEmpty && !name2Value.isEmpty && !name3Value.isEmpty && !name4Value.isEmpty {

        return true

    }

    return false

}

Ok, funciona al 50% por ahora.

Cuando escribo un carácter en cada campo de texto, el botón todavía está deshabilitado.

Cuando agrego un segundo a cualquier campo de texto, el botón se habilita, etc.

¿Alguien podría ayudarme con esto?

Saludos y gracias!

Respuestas a la pregunta(5)

Su respuesta a la pregunta