Reducing the number of brackets in Swift

后端 未结 7 1957
离开以前
离开以前 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:13

    In swift you have to add braces even if there is just one statement in if:

    if num == 0 {
      // Do something
    }
    

    You cannot leave the braces, that how swift if statement work.

提交回复
热议问题