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.

Fix Swift Framework Error: Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.2.4 compiler:

Chances are you upgraded to the latest Xcode and along with it, your Swift compiler is updated as well. Then existing projects using a particular project have stopped working with similar error such as.

Module compiled with Swift 5.1.3 cannot be imported by the Swift 5.2.4 compiler:

/Users/PauloOrquilo/Documents/Development/Mobile/Training/CoreData/Sync/iOSDemo/Carthage/Build/iOS/Sync.framework/Modules/Sync.swiftmodule/x86_64.swiftmodule

Or you are checking out some hosted on code on Github using some framework, the framework might have been built using an older compiler version, if you try to run the associated .xcodeproj or .xworkspace it won’t build the project.

This is only for frameworks built using Carthage. I haven’t experienced this on CocoaPods. Make sure you have Carthage installed – check this documentation on how to install Carthage – https://github.com/Carthage/Carthage

To fix, take a backup of your project, or better yet make sure you are using version control. Delete the framework that is failing from your project.

Go to the Project directory from the Terminal and make sure the Cartfile is available and run. Choose the right platform for the app.

carthage update --platform IOS

It should create a newly .framework on the Carthage/Build folder.

On Xcode go the General Tab and under Framework, Libraries and Embedded Content. Drag and drop the files

Then finally, try running the build and your project should be working.

Hope you find this tip useful.