how does appdelegate become the ui appdelegate?

The answer to this question varies a little depending on which version of Xcode/Swift/iOS you are talking about, but the essential process is the same.

If you create a project in Xcode that uses the UIKit AppDelegate lifecycle then you will see the line @main at the start of the AppDelegate.swift file.

This tells the compiler that this file contains the UIApplicationDelegate implementation. The compiler then synthesises a main function for you that performs all of the required setup, including creating an instance of the AppDelegate and assigning it to the UIApplication instance.

In earlier versions of Swift you would see @UIApplicationMain that does essentially the same thing.

You can omit the @main/@UIApplicationMain and create your own main that does all of the required work, but this generally isn’t required.

With SwiftUI you now have the option of using SwiftUI lifecycle rather than UIKit lifecycle when you create the project. In this case you have an App struct. This file still contains the @main and is used to launch your app’s view hierarchy.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top