dimanche 4 septembre 2016

if else shorthand crashes on setting bool in swift

I literally have 4 line of code.

var bool = true

let textField1 = UITextField()

let textField2 = UITextField()

bool ? textField1.enabled = false : textField2.enabled = false

The above code fails with following error.

enter image description here

if I write the following way the code works

if bool {

   textField1.enabled = false
}
else {

   textfield2.enabled = false
}

If I write the following way then short hand of if else works

bool ? print("It's True") : print("It's False")

Why is my code failing?

Aucun commentaire:

Enregistrer un commentaire