Comparing two uiTextFields

Dears,


How can I compare if the content of two uiTextFields are different to empty?


I was tryting to do something like this but I got the following error: Comparing non-optional value of type 'String' to nil always returns true

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        self.view.endEditing(true)
        
        let apresentacao: String = tfApresentacao.text!
        let corte: String = tfCorte.text!
        
        if apresentacao != nil && corte != nil {
            calcJornadaTrabalhada()
            
            lbEvento.isHidden = false
            lbTempo.isHidden = false
        }
        
        
    }


Thanks

Answered by Claude31 in 336288022

Use isEmpty


        if apresentacao?.text != nil && corte?.text != nil && !apresentacao!.text!.isEmpty && !corte!.text!.isEmpty {
Accepted Answer

Use isEmpty


        if apresentacao?.text != nil && corte?.text != nil && !apresentacao!.text!.isEmpty && !corte!.text!.isEmpty {

Good idea, thanks!

Comparing two uiTextFields
 
 
Q