1
Good night, my friends
I am having difficulty in the following, I intend that the user receive a warning when the textfield is empty and if it pressed the button.
tried with the if condition (textFiel.text == "") but it didn’t work out, thanks for our help.
@IBAction func botton(_ sender: Any) {
let celcius = Float(textFiel.text!)!
let Fahrenheit:Float = (9 * celcius + 160) / 5
label.text = "\(Fahrenheit)"
if (textFiel.text == "") {
label.text = "Por favor digite algo"
}
}
Good morning, Edson of the error in the syntax (!textFiel.isEmpty), says that Value of type 'Uitextfiel' has no Member ' isEmpry ' It seems that the error is the declaration of variables or in the construction of the algorithm, all suggestions seem great just do not execute
– An. Jorge
Anselmo, I’ve fixed the code now.
– Edson Guido
This edition worked perfectly. thanks Edson and everyone for the help.
– An. Jorge
guard textField.text?.isEmpty == false else {
– Leo Dabus
For iOS 10+ Uitextfield has a property called
hasText
exactly for this– Leo Dabus