How to set up your SwiftUI Project with AppDelegate and SceneDelegate

KD Knowledge Diet
2 min readJun 30, 2022

As Apple released the SwiftUI Lifecycle, AppDelegate or SceneDelegate are no longer automatically created in the project. In fact, you can do almost anything with Notification Event without having to use AppDelegate or SceneDelegate. Nevertheless, if there is AppDelegate or SceneDelegate, the advantage is that it is easier to organize the code.

Create SwiftUI Project

Create SwiftUI Project

Now you will see these files.

Your Created Project

You can check there’s no more AppDelegate and SceneDelegate.

Implement AppDelegate

[1] Create AppDelegate.swift

AppDelegate

[2] Add boilerplate code to AppDelegate

AppDelegate.swift

[3] Attach AppDelegate on your App

Your App

[4] Test

Test Code

Run the application and you will see App Did Launch is printed out.

Implement SceneDelegate

[1] Create SceneDelegate File

Create SceneDelegate.swift

[2] Add boilerplate code to SceneDelegate

SceneDelegate.swift

[3] Connect your SceneDelegate in your AppDelegate

Connect SceneDelegate.swift in AppDelegate.swift
AppDelegate.swift

[4] Test

Scene Delegate

Now you will see “SceneDelegate is connected!” message is printed out in the console!

Conclusion

Create AppDelegate

  1. Create AppDelegate.swift
  2. Add Boilerplate Code
  3. Attach it on App with @UIApplicationDelegateAdaptor

Create SceneDelegate

  1. Create SceneDelegate.swift
  2. Add Boilerplate Code
  3. Connect it through func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration.

--

--

KD Knowledge Diet

Software Engineer, Mobile Developer living in Seoul. I hate people using difficult words. Why not using simple words? Keep It Simple Stupid!