Skip to content

Instantly share code, notes, and snippets.

@eldaroid
Last active July 28, 2024 10:11
Show Gist options
  • Save eldaroid/14f440081695cc47a64b65aafaea3781 to your computer and use it in GitHub Desktop.
Save eldaroid/14f440081695cc47a64b65aafaea3781 to your computer and use it in GitHub Desktop.
Исследуем жизненный цикл iOS Scene (методы SceneDelegate)
final class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
// Настройка окна приложения
window = UIWindow(windowScene: windowScene)
let initialViewController = ViewController()
window?.rootViewController = initialViewController
window?.makeKeyAndVisible()
}
// MARK: - SceneDelegate Lifecycle
func sceneDidDisconnect(_ scene: UIScene) {
Logger.shared.log("😍 - 0) sceneDidDisconnect")
}
func sceneDidBecomeActive(_ scene: UIScene) {
Logger.shared.log("😍 - 3) applicationDidBecomeActive")
}
func sceneWillResignActive(_ scene: UIScene) {
Logger.shared.log("😍 - 4) applicationWillResignActive")
}
func sceneDidEnterBackground(_ scene: UIScene) {
Logger.shared.log("😍 - 5) applicationDidEnterBackground")
}
func sceneWillEnterForeground(_ scene: UIScene) {
Logger.shared.log("😍 - 6) applicationWillEnterForeground")
}
}
@eldaroid
Copy link
Author

eldaroid commented Jun 19, 2024

Наглядная визуализация методов жизненного цикла SceneDelegate:

Сценарии вызовов каждого метода:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment