Swift's guard keyword

前端 未结 13 2317
一整个雨季
一整个雨季 2020-11-27 09:03

Swift 2 introduced the guard keyword, which could be used to ensure that various data is configured ready to go. An example I saw on this website demonstrates a

13条回答
  •  死守一世寂寞
    2020-11-27 09:47

    Like an if statement, guard executes statements based on a Boolean value of an expression. Unlike an if statement, guard statements only run if the conditions are not met. You can think of guard more like an Assert, but rather than crashing, you can gracefully exit.

    refer to: http://ericcerney.com/swift-guard-statement/

提交回复
热议问题