TechnologiesSwiftUI

UIApplicationDelegateAdaptor struct

iOSmacOStvOSwatchOSvisionOS✓ renders

A property wrapper type that you use to create a UIKit app delegate.

How it works

Use the UIApplicationDelegateAdaptor property wrapper to designate a custom app delegate class within a SwiftUI App lifecycle. SwiftUI apps declared with the App protocol no longer have a UIApplicationDelegate of their own, yet some UIKit-era callbacks — remote-notification registration, deep-link handling, scene configuration — are still delivered only to a delegate object. By annotating a stored property with this wrapper, you tell SwiftUI to instantiate your delegate type, install it as the application's delegate, and keep it alive for the lifetime of the app. Reach for it whenever you need to receive UIApplicationDelegate callbacks that the pure SwiftUI lifecycle does not expose.

  1. Conform a class to UIApplicationDelegate

    The wrapper adapts an existing delegate type, so you first supply a class that conforms to UIApplicationDelegate (typically also NSObject and ObservableObject). This is the object that implements the app-level callbacks you care about. In the example it is referred to as AppDelegate, the type passed to the wrapper.

  2. Declare the property with @UIApplicationDelegateAdaptor

    Apply the wrapper as an attribute on a stored property of your App. SwiftUI creates one instance of the delegate type and binds it to the property. The example shows the canonical form @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate, where the wrapped delegate value is the live delegate instance.

  3. Pass the delegate type with the metatype initializer

    The initializer takes the delegate's metatype — AppDelegate.self — rather than an instance, because SwiftUI owns the instantiation and lifecycle. This is what lets the framework install the object as the application's delegate at launch instead of you constructing and assigning it yourself, as the @UIApplicationDelegateAdaptor(AppDelegate.self) call in the example illustrates.

  4. Place the property inside your App, not a View

    Because it bridges the application lifecycle, the wrapper belongs on the type conforming to App — that is the scope SwiftUI uses to wire up the delegate before any scene appears. The surrounding UIApplicationDelegateAdaptorDemo view here only documents the declaration in Text; in a real project the same var delegate line lives alongside your Scene body.

  5. Read the delegate, and observe it when needed

    Once declared, the wrapped delegate is an ordinary property you can read to reach state your callbacks have collected. If your delegate also conforms to ObservableObject, an overload of the wrapper publishes it into the environment as an @ObservedObject, so child views update when the delegate's @Published values change — turning the bridge described in the example's footnote Text into a live source of data.

Try it — Change the type in @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate to a class that prints from application(_:didFinishLaunchingWithOptions:), and watch that callback fire at launch — proof the wrapper installed your object as the real application delegate.

Example & preview

Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.

UIApplicationDelegateAdaptor.swift
struct UIApplicationDelegateAdaptorDemo: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 12) {
            Label("App Delegate", systemImage: "app.badge")
                .font(.headline)
            Text("@UIApplicationDelegateAdaptor(AppDelegate.self) var delegate")
                .font(.system(.caption, design: .monospaced))
                .foregroundStyle(.secondary)
            Text("Bridges a UIApplicationDelegate into the SwiftUI App lifecycle.")
                .font(.footnote)
        }
        .padding()
    }
}
Live preview
App Delegate @UIApplicationDelegateAdaptor(AppDelega… var delegate Bridges a UIApplicationDelegate into the SwiftUI App lifecycle.
App Delegate @UIApplicationDelegateAdaptor(AppDelega… var delegate Bridges a UIApplicationDelegate into the SwiftUI App lifecycle.
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →