How to Add SceneDelegate to an Existing Storyboard Project in XCode

I have an old project previously built on IOS12 and now trying to add new features on IOS 13. One of the things I’m trying to wrap my head around before I start adding new functionalities to my app is the introduction of UIWindowScene and the support for multiple window for iOS and iPadOS.

What is UIWindowScene? As per the documentation – this is an object that manages one instance of your app’sUI, including one ore more windows that is displayed from that scene.

Before iOS 13, the AppDelegate is the starting point of an App. It was in charge of setup, state handling, and other logic as such as below:

  • setup first view controller – root view controller
  • configure app settings and startup components
    • logging
    • cloud services
    • persistent container
  • register push notification handlers and respond to push notifications sent to the app
  • respond to app lifecycle events
    • entering background
    • resuming app
    • existing app

My didFinishLaunchingWithOptions method implemented on the AppDelegate looks like this.

self.window object on the snippet above is a property of the AppDelegate and is the only one window my app uses. It manages the app’s UI, dispatch events to views and the main backdrop to display the app’s content.

On iOS 13, the AppDelegate is responsible for the initial setup only. The SceneDelegate takes over some of it’s roles, one of which is the window and is replaced by a scene. An app can now have more than one instance of the window/scene. So now you can have an app with multiple scenes.

For example for a word processor app could have every text document as a scene.

Now that the concepts has been discussed and hopefully clear. The following files on my existing project needs to be modified.

  • Adding a SceneDelegate class
    • Either create a new class SceneDelegate and paste the boiler plate code or create a new project on Xcode and copy the SceneDelegate from that project.
  • Updating the AppDelegate class
    • Existing implementation methods can be removed and add the two scene related implementation methods
  • Updating the info.plist file
    • for this one click on + icon the last item of the info.plist then choose Application Scene Manifest
    • Expand that and replicate the options as per the screenshot.

Fingers crossed all changes right, build your app. Get that sweet Build Succeeded message. Your app is now running on its own instance of the window.

Leave a Reply

Your email address will not be published. Required fields are marked *