Reducing the number of brackets in Swift

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

    its very simple : in Swift 4

        playButton.currentTitle == "Play" ? startPlay() : stopPlay()
    

    Original Code is

        if playButton.currentTitle == "Play"{
         StartPlay()
        }else{
         StopPlay()
        }
    

提交回复
热议问题