[iOS] if let Shorthand

유인호·2024년 1월 3일
0

iOS

목록 보기
6/54

Swift 5.7에서 추가된 구문
기존에는

let age: Int? = 24

if let age = age {
	print(age)
}

이렇게 age = age를 사용하여 중복되는감이 없지 않아 있었는데,

let age: Int? = 24

if let age {
	print(age)
}

이렇게 사용하여 조금 더 짧게 사용할 수 있게 바뀌었다.


자매품

let age: Int? = 24

guard let age else { return } 

print(age)

guard let도 축약 가능

profile
🍎Apple Developer Academy @ POSTECH 2nd, 🌱SeSAC iOS 4th

0개의 댓글