MacOS-App: Basic Overview > Part-1

1. Files – Basic

1) AppDelegate.swift

• It is responsible for managing the overall life cycle of the app.

앱의 전반적인 생명 주기를 관리하는 역할을 합니다.

• Handles key events such as when the app is launched, terminated, or transitions to the background.

앱이 실행되거나 종료될때, 백그라운드로 전환될 때 등의 주요 이벤트를 처리합니다.

• applicationDidFinishLaunching(_:)
>> Called immediately after the app starts. Used for initialization tasks (e.g. connecting to a database, loading initial settings, etc.).

>> 앱이 실행된 직후 호출됩니다. 초기화 작업(예: 데이터베이스 연결, 초기 설정 로드 등)에 사용됩니다.

• applicationWillTerminate(_:)
>> Called just before the app is about to exit. Useful for resuming a suspended task.

>> 앱이 종료되기 직전에 호출됩니다. 일시 중지된 작업을 다시 시작할 때 유용합니다.

• applicationDidBecomeActive(_:)
>> Called when the app becomes active. Useful for resuming paused tasks.

>> 앱이 활성화되었을 때 호출됩니다.일시 중지된 작업을 다시 시작할 때 유용합니다.

• applicationWillResignActive(_:)
>> Called just before the app becomes inactive. In games, this can be used to pause the game or save important data.

>> 앱이 비활성화되기 직전에 호출됩니다. 게임에서는 일시정지 상태로 전환하거나 중요한 데이터 저장에 활용할수 있습니다.

2) ViewController.swift

• This is a controller that manages the user interface (UI). In MacOS, it inherits “NSViewController” and is responsible for the operation of one screen or view.

사용자 인터페이스(UI)를 관리하는 컨트롤러 입니다.
MacOS에서는 “NSViewController”를 상속하며, 하나의 화면 또는 뷰(View)의 동작을 담당합니다.

• viewDidLoad()
>> Called after the view is loaded into memory. Performs initial UI setup, data binding, event listener registration, etc.

>> 뷰가 메모리에 로드된 후 호출됩니다. 초기 UI 설정, 데이터 바인딩, 이벤트 리스너 등록 등을 수행합니다.

• viewWillAppear() / viewDidAppear()
>> Called just before/after the view appears on the screen. Good for tasks that need to be performed every time the screen appears, such as refreshing data.

>> 뷰가 화면에 나타나기 직전/직후에 호출됩니다. 화면이 표시될 때마다 수행해야 하는 작업(예: 데이터 새로고침 등)에 적합합니다.

• viewWillDisappear() / viewDidDisappear()
>> Called just before/after the view disappears. Used for resource cleanup or state saving.

>> 뷰가 사라지기 직전/직후에 호출됩니다. 리소스 정리나 상태 저장에 사용됩니다.

2. Files – Flow

1) Run app -> Call “applicationDidFinishLaunching(_:)” of “AppDelegate”

앱 실행 -> “AppDelegate”의 “applicationDidFinishLaunching(_:)” 호출

2) Load window/view -> Call “viewDidLoad()” of “ViewController”

윈도우/뷰 로드 -> “ViewController”의 “viewDidLoad()” 호출

3) User interaction (button clicks, etc.) -> Handled in “ViewController”

사용자 상호작용(버튼 클릭 등) -> “ViewController” 에서 처리

4) Terminate app -> Call “applicationWillTerminate(_:)” of “AppDelegate”

앱 종료 -> “AppDelegate”의 “applicationWillTerminate(_:)” 호출

Leave a Reply