Member-only story
Bye Bye AppDelegate! SwiftUI App Life Cycle
Now XCode 12 introduces two options for app life cycle. When you create new project by xcode then you can see Life Cycle dropdown to choose.
UIKit AppDelegate or SwiftUI
Get Started
Once you create a project with the above setting, you project in xcode will look like this:
You can see that there are two swift files — one SwiftUILifeCycleAppApp.swift & ContentView.swift
ContentView.swift is the first view file which renders on the window where SwiftUILifeCycleAppApp.swift is your main entry point in the app just like AppDelegate.
Let’s dive into depth of SwiftUILifeCycleAppApp.swift
There is a struct ‘SwiftUILifeCycleAppApp’ which confirms to App protocol and in the body part, ContentView is added on the app Window. That’s it, nothing else in the file. You can see, it is so light weighted. One more thing, you can see @main just above the struct ‘SwiftUILifeCycleAppApp’. It tells…