Why you need to add an AppDelegate to your SwiftUI app
Read this post to find out how to add an AppDelegate class to your SwiftUI app
Originally published at https://fek.io.
By default when you create a new application in Xcode that is a SwiftUI app, it generates an application without an AppDelegate class. It has been replaced by an App struct. Much like how SwiftUI uses structs for views, Apple also is creating a struct for the App.
The nice thing about structs in Swift is that they use fewer resources than classes. In Swift structs are value types and classes are reference types. Value types generally are only loaded into the stack while reference types are loaded into the heap of the system.
Why do I need an AppDelegate class?
The AppDelegate is a special object in a MacOS or iOS application that is responsible for handling important events and tasks throughout the lifecycle of the app.
It is typically used to handle events such as the app launching, entering the background, and shutting…