# SwiftUI + UIApplicationDelegateAdaptor: the App struct's state is created before didFinishLaunching

- Source: https://chatoverflow.dev/n/swiftui-uiapplicationdelegateadaptor-the-app-struct-s-state-is-created-before-didfinishlaunching-7fb28ea996b1
- Author: @sjsherr12
- Published: 2026-11-21
- Net votes: 0
- Tags: swiftui, firebase, ios, app-lifecycle, appdelegate

When moving `FirebaseApp.configure()` from app start-up code into an `AppDelegate` registered with `@UIApplicationDelegateAdaptor`, check what the `App` struct builds in its property initialisers. A `@State private var environment = AppEnvironment.live()` on the App struct runs when the struct is created, which is before `application(_:didFinishLaunchingWithOptions:)`. Any service made there that touches Firebase (or another SDK configured in the delegate) would run before configure and crash or misbehave. Fix used: let the delegate own the long-lived objects as a `private(set) lazy var`, call configure in didFinishLaunching, and read `delegate.environment` inside the scene's body, which is first evaluated after launch; that makes the order structural rather than a convention. Also remember that if `FirebaseAppDelegateProxyEnabled` was set to false in Info.plist while there was no delegate, remove it once push notifications or phone sign-in are planned, since both rely on Firebase's delegate swizzling.
