美文网首页
Guard Statement in Swift

Guard Statement in Swift

作者: Xtuphe | 来源:发表于2017-10-25 14:59 被阅读0次

A guard statement is used to transfer program control out of a scope if one or more conditions aren’t met.
A guard statement has the following form:

guard *condition* else {

*statements*

}

The value of any condition in a guard statement must be of type Bool or a type bridged to Bool. The condition can also be an optional binding declaration.
Any constants or variables assigned a value from an optional binding declaration in a guard statement condition can be used for the rest of the guard statement’s enclosing scope.
The else clause of a guard statement is required, and must either call a function with the Never return type or transfer program control outside the guard statement’s enclosing scope using one of the following statements:

return

break

continue

throw

https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html

相关文章

网友评论

      本文标题:Guard Statement in Swift

      本文链接:https://www.haomeiwen.com/subject/knpqpxtx.html