Why you need to add an AppDelegate to your SwiftUI app

David Fekke
3 min readJan 26

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 down. The AppDelegate is also used to set up the initial state of the app, such as creating the main window and loading any necessary data, resources, etc… Additionally, it can handle other system-level events such as push notifications and URL opening.

The app struct that is part of the standard Xcode SwiftUI template does not handle all of the application lifecycle and external events that are handled by the AppDelegate class. This is why you may need to add this class to your app.

SwiftUI file structure

When you create a new SwiftUI iOS app in Xcode, it will create a folder named after your app, and two files for the App struct and the ContentView struct. They look like the following;

// SampleApp.swift
import SwiftUI

struct SampleApp: App {
var body: some Scene {
WindowGroup {

// ContentView.swift
David Fekke

I am a software engineer and commercial pilot in jacksonville, Fl. I also produce videos for the Polyglot Engineer Channel on YouTube.