> **앱이 처음 시작될 때 시스템이 코드를 어떤 순서로 실행하는지 알아보자**
<br>
## 과정
실행에 필요한 대부분의 복잡한 과정은 UIKit이 자동으로 처리해준다.
실행 과정에서 UIKit은 [[AppDelegate와 UIApplicationDelegate|app delegate]]의 메서드를 호출하여 사용자 상호작용과 앱의 로직을 준비할 수 있도록 한다.
<br>
![[app_launch_sequence.png|center|450]]
<br>
1. **사용자 혹은 시스템에 의한 앱 실행**
2. **`main()` 함수 실행 (Xcode 제공)**
3. **`UIApplicationMain()` 함수 호출**
- `main()` 함수에서 `UIApplicationMain()` 함수를 호출해서, `UIApplication` 및 app delegate 객체를 생성함
4. default 스토리보드 로드 **(optional)**
- UIKit이 Info.plist나 Xcode의 Custom iOS Target Properties 탭에서 지정한 default 스토리보드를 로드함
- default 스토리보드를 사용하지 않는 경우 이 단계를 생략함
5. **`application(_:willFinishLaunchingWithOptions:)` 메서드 호출**
- UIKit이 app delegate의 `application(_:willFinishLaunchingWithOptions:)` 메서드를 호출함
6. **state restoration 수행**
- UIKit에 의해 state restoration이 수행되며, 이로 인해 app delegate 및 앱의 뷰 컨트롤러에서 추가적인 메서드가 실행됨
7. **`application(_:didFinishLaunchingWithOptions:)` 메서드 호출**
- UIKit이 app delegate의 `application(_:didFinishLaunchingWithOptions:)` 메서드를 호출함
<br>
해당 과정이 완료된 후, 시스템은 app delegate나 scene delegate를 사용하여 앱의 UI를 표시하고 life cycle을 관리한다.
---
**참고 문서**
https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app/about_the_app_launch_sequence
<br>
<br>
<br>
<br>