반응형
► Swift/문법
-
[Swift] Optional Unwrapping - 옵셔널 바인딩(if let)► Swift/문법 2024. 2. 2. 20:02
if, while, guard 3가지 방식으로 옵셔널바인딩을 할 수 있다. while문은 거의 안쓰이고, if와 guard문을 주로 이용한다. 오늘은 if문을 알아보려고 한다. if let 메커니즘 ▼ 샘플코드 import Foundation func test(_ n: Int) -> Int{ let nilChk:Int? = nil // output: nil if let optChk = nilChk { // when nilChk is not nil print(optChk)// output: 8 print(nilChk)// output: Optional(8) print("-1-")// output: -1- }else{ // when nilChk is nil // print(optChk) // output: ..