Early Exit
A guard statement, like an if statement, executes statements depending on the Boolean value of an expression. You use a guard statement to require that a condition must be true in order for the code after the guard statement to be executed. Unlike an if statement, a guard statement always has an else clause—the code inside the else clause is executed if the condition is not true.
If the guard statement’s condition is met, code execution continues after the guard statement’s closing brace. Any variables or constants that were assigned values using an optional binding as part of the condition are available for the rest of the code block that the guard statement appears in.
If that condition is not met, the code inside the else branch is executed. That branch must transfer control to exit the code block in which the guard statement appears. It can do this with a control transfer statement such as return, break, continue, or throw, or it can call a function or method that doesn’t return, such as fatalError().
'SWIFT' 카테고리의 다른 글
스위프트 ARC와 순환참조와 클로저 (0) | 2017.09.07 |
---|---|
AlertView 띄우기 (iOS7,8)- Swift (0) | 2015.01.21 |
Swift Singletons 구현 방법 (0) | 2014.12.09 |
Apple Swift Programming Language for KOREAN - 배포중 (0) | 2014.06.12 |