0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ios13から導入されたSceneDelegateの概要を3分でさっとおさらい

Last updated at Posted at 2020-12-03

ScreenDelegateとは?

Xcode11から、新しくプロジェクトを作ると、SceneDelegate.swiftという新しい設定ファイルが作成されるようになった。

iOS13未満では、AppDelegateがアプリのエントリーポイントだった。
ライフサイクル+セットアップ+画面の表示の全てのコード存在し、AppDelegateは肥大化しやすかった。
しかし、iOS13からは、これが解決する。
AppDelegateに、ライフサイクル+セットアップ。SceneDelegateに、画面のライフサイクル。
と、今までのAppledegateの処理を2ファイルに分割し、コードのスパゲッティ化を防ぐ

詳細な説明

AppDelegate

アプリのエントリーポイント。
アプリレベルのライフサイクルが呼ばれる。
デフォルトでは3種のメソッドが存在

  1. func application(_:didFinishLaunchingWithOptions:) -> Bool
  2. func application(_:configurationForConnecting:options:) -> UISceneConfiguration
  3. func application(_:didDiscardSceneSessions:)

SceneDelegate

UIWinndow+UIScreenの処理を担当
画面のライフサイクルを担当(画面の生成、消滅、再生成など)
デフォルトでは以下6つのメソッドが存在

  1. scene(_:willConnectTo:options:)
  2. sceneDidDisconnect(_:)
  3. sceneDidBecomeActive(_:)
  4. sceneWillResignActive(_:)
  5. sceneWillEnterForeground(_:)
  6. sceneDidEnterBackground(_:)

大体名前からどのライフサイクルのどの時点で発火するか分かるぐらい良い命名だ。

参考

この記事は、以下の英記事を荒く要約した物です。
https://medium.com/@kalyan.parise/understanding-scene-delegate-app-delegate-7503d48c5445

0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?