Apple Developer Documentation

Overview

App의 루트와 같다.

실행주기, 백그라운드 상태, 기기의 환경변화 관련, 알림, 타 기능과 연결 등의 관리를 해준다.

App Launch

Apple Developer Documentation

Untitled

  1. 앱은 사용자가 명시적으로 실행하거나 시스템에 의해 암시적으로 실행됩니다.
  2. Xcode가 제공하는 main 함수는 UIKit의 UIApplicationMain() 함수를 호출합니다. (UIApplicationMain() 는 Int32 를 return하는 함수이지만 이 함수는 return을 절대 하지 않습니다.)
  3. UIApplicationMain() 함수는 UIApplication 객체와 App Delegate를 생성합니다. (UIApplication 객체는 싱글턴 객체입니다.)
  4. UIKit은 메인 스토리보드나 nib 파일에서 앱의 기본 인터페이스를 로드합니다.
  5. UIKit은 앱 델리게이트 willFinishLaunchingWithOptions 함수를 호출합니다.
  6. UIKit은 추가적인 앱 델리게이트 메소드들과 뷰 컨트롤러를 호출하는 상태값 복원을 실행합니다.
  7. UIKit은 앱 델리게이트 didFinishLaunchingWithOptions 함수를 호출합니다.

초기화가 완료되면 시스템은 UI를 표시하고 앱 라이프 사이클을 관리하기 위해 Scene Delegate 나 App Delegate 를 사용합니다.

How to access AppDelegate

let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext