-
guard Statement - Conditional StatementsiOS/π Swift 2020. 11. 4. 10:30
/* Syntax */ guard condition else { statements } guard optionalBinding else { statements }
if μμ μ°¨μ΄
1. guard λ 쑰건μ μκ° λμ΄λλλΌλ μ½λκ° μ€μ²©λμ§ μμ΅λλ€.
2. guard λ else blockμ μλ΅ν μ μμ΅λλ€.
3. Bindingμ μ¬μ©ν λ³μ νΉμ μμλ₯Ό else block μ΄νμ κ³μ μ¬μ©ν μ μμ΅λλ€.
λ¨, else block μμλ μ¬μ© λΆκ°
νΉμ§
1. else blockμ condition νΉμ optionalBinding μ΄ μ€ν¨νμ κ²½μ° μ§μ ν©λλ€.
2. guard μ else block λ΄μμ return νΉμ throw λ₯Ό ν΅ν΄ Early Exit ν΄μΌ ν©λλ€. ( μλ μ μ»΄νμΌ μλ¬ )
μ¦, guard Statement λ₯Ό νΈμΆν μ€μ½νλ₯Ό λ°λμ μ’ λ£μμΌμΌ ν©λλ€.
λ.
μ΄μ κΈ: Type Safety - Data Types
'iOS > π Swift' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
In-Out Parameters - Functions (0) 2020.11.06 Parameters - Functions (0) 2020.11.06 Type Safety - Data Types (0) 2020.11.03 Type Inference - Data Types (0) 2020.11.03 3 features of First Class Citizen - Function (0) 2020.11.02