Reducing the number of brackets in Swift

后端 未结 7 1945
离开以前
离开以前 2021-02-01 19:53

Does anyone know if there is a way to use some kind shorthand in swift? more specifically, leaving out the braces in things like IF statements... eg

if num == 0
         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-01 20:01

    It is called shorthand if-else condition. If you are into iOS development in Swift, then you can also manipulate your UI objects' behaviour with this property.

    For e.g. - I want my button to be enabled only when there is some text in the textfield. In other words, should stay disabled when character count in textfield is zero.

    button.enabled = (textField.characters.count > 0) ? true : false

提交回复
热议问题