HIT해
[iOS/SwiftUI] defer 본문
728x90
defer란?
Swift에서 코드 블록의 마지막에 실행될 코드를 예약할때 사용된다.
defer 블록내의 코드는 해당 코드 블록이 종료되기 직전에 실행된다.
자원 해제, 상태 복구, 정리 작업과 같이 코드 블록이 끝날 때 반드시 수행되어야하는 작업을 지정하는데 쓰인다.
func exampleFunction() {
print("Start")
defer {
print("Deferred: This will run at the end of the function")
}
print("End")
}
실행결과
Start
End
Deferred: This will run at the end of the function
'Swift > Swift CS' 카테고리의 다른 글
[iOS/SwiftUI] NavigationStack 공식문서 뜯어보기 (0) | 2024.08.31 |
---|---|
[iOS/SwiftUI] TCA finish() 알아보기 (0) | 2024.08.30 |
[iOS/TCA] TwoCounters로 TCA Scope알아보기 (0) | 2024.08.30 |
[iOS/TCA] 01-GettingStarted-Animations (0) | 2024.08.29 |
[iOS/SwiftUI] TCA 프로젝트 뜯어보기 (0) | 2024.08.26 |