In iOS, the SceneDelegate
is a class that is responsible for managing the scenes in your app. A scene is a discrete unit of your app's user interface, such as a window or tab. The SceneDelegate
class provides methods that are called at various points in the lifecycle of a scene, such as when a scene is about to be displayed, or when a scene is about to be destroyed.
The SceneDelegate
class is typically used to manage the state of a scene and to respond to events that affect the scene. For example, the SceneDelegate
class might be used to manage the size and position of a window, or to respond to changes in the device's orientation.
In general, the SceneDelegate
class is an optional part of the iOS app architecture, and you do not need to use it in your app unless you need to manage multiple scenes. If you only have one scene in your app, you can use the AppDelegate
class to manage the lifecycle of your app instead.
Remove the SceneDelegate
There might be some reason we probably don't want the SceneDelegate
class. To remove the SceneDelegate
class from your iOS app, you can follow these steps:
- Open your project in Xcode and in the Project Navigator, navigate to the
SceneDelegate.swift
file and delete it. - In the Project Navigator, navigate to the
AppDelegate.swift
file. - In the
AppDelegate
class, remove theUISceneDelegate
protocol from the class declaration. - In the
AppDelegate
class, remove thevar window: UIWindow?
property. - In the
AppDelegate
class, remove the following methods:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
func sceneDidDisconnect(_ scene: UIScene)
func sceneDidBecomeActive(_ scene: UIScene)
func sceneWillResignActive(_ scene: UIScene)
func sceneWillEnterForeground(_ scene: UIScene)
func sceneDidEnterBackground(_ scene: UIScene)
6, In the Info.plist
file, remove the UISceneManifest
key and its associated dictionary.
After completing these steps, the SceneDelegate
class will be removed from your app, and the AppDelegate
class will be the only class responsible for managing the lifecycle of your app. However, note that removing the SceneDelegate
class will also remove the ability to manage multiple scenes in your app, so you should only do this if you do not need this functionality.