꾸준히 안타치기
App's Life Cycle 화면생명주기, AppDelegate, SceneDelegate 본문
화면생명주기와, 앱의 생명주기가 있다.
화면생명주기와 앱의 생명주기를 분리해서 생각하자.
⭐️ 화면생명주기 뷰컨트롤러에서 실행

viewDidLoad() - 뷰의 로딩이 완료되었을때 시스템에 의해 자동으로 호출됨(메모리에 올림)
리소스를 초기화하거나 초기화면을 구성하는 용도로 사용
처음 한번만 실행해야하는 초기화 코드가 잇을 경우 여기에 작성한다.
viewWillAppear() - 뷰가 나타나기 직전에 호출
다른뷰로 갔다가 다시 돌아오는 상황에 해주고 싶은 처리
ex) 팝업창 띄울때 / 화면을 다가리는 팝업과 풀페이지의 생명주기가 다름
viewDidAppear() - 뷰가 화면에 나타나 직후에 실행됨.
뷰가 나타났다는 것을 컨트롤러에게 알림, 화면에 적용될 애니메이션을 그려줌
이것을 제외하고 viewDidAppear와 viewWillAppear는 거의 비슷
viewWillDisappear() - 뷰가 사라지기 직전에 호출
뷰가 삭제 되려고 하고 있는 것을 뷰컨트롤러에 통지
viewDidDisappear() - 뷰컨트롤러의 뷰가 제거 되었음을 알려줌
⭐️ 앱의생명주기 SceneDelegate에 있는 내용
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
// This occurs shortly after the scene enters the background, or when its session is discarded.
// Release any resources associated with this scene that can be re-created the next time the scene connects.
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
}
func sceneDidBecomeActive(_ scene: UIScene) {
// Called when the scene has moved from an inactive state to an active state.
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
}
func sceneWillResignActive(_ scene: UIScene) {
// Called when the scene will move from an active state to an inactive state.
// This may occur due to temporary interruptions (ex. an incoming phone call).
}
func sceneWillEnterForeground(_ scene: UIScene) {
// Called as the scene transitions from the background to the foreground.
// Use this method to undo the changes made on entering the background.
}
func sceneDidEnterBackground(_ scene: UIScene) {
// Called as the scene transitions from the foreground to the background.
// Use this method to save data, release shared resources, and store enough scene-specific state information
// to restore the scene back to its current state.
}
}
https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle/
Apple Developer Documentation
developer.apple.com
https://medium.com/good-morning-swift/ios-view-controller-life-cycle-2a0f02e74ff5
iOS View Controller Life Cycle
Introduction:
medium.com
UIViewController lifecycle methods | Learning Xamarin Studio
The following is a flowchart depicting a UIViewController lifecycle:
www.prod.packt.com
참고글
https://sihyungyou.github.io/iOS-lifecycle/
iOS) 앱/Scene 생명주기
App/Scene Life Cycle
sihyungyou.github.io
'iOS > Basic Study' 카테고리의 다른 글
Completion handler (0) | 2023.04.06 |
---|---|
iOS로드맵 / swiftUI (0) | 2023.01.12 |
테이블뷰, 컬렉션뷰셀 세팅 / UIKit / 이미지모드 (0) | 2022.09.15 |
탭맨 라이브러리 사용하기 (0) | 2022.09.11 |
AVFoundation 배경음악 넣기 / 타이머 만들기 (0) | 2022.09.09 |