init(_:)
Creates an AppKit app delegate adaptor.
Declaration
@MainActor @preconcurrency init(_ delegateType: DelegateType.Type = DelegateType.self)Parameters
- delegateType:
The type of application delegate that you define in your app, which conforms to the Nsapplicationdelegate protocol.
Discussion
Call this initializer indirectly by creating a property with the NSApplicationDelegateAdaptor property wrapper from inside your App declaration:
@main
struct MyApp: App {
@NSApplicationDelegateAdaptor private var appDelegate: MyAppDelegate
var body: some Scene { ... }
}SwiftUI initializes the delegate and manages its lifetime, calling upon it to handle application delegate callbacks.
If you want SwiftUI to put the instantiated delegate in the Environment, make sure the delegate class also conforms to the ObservableObject protocol. That causes SwiftUI to invoke the init(_:) initializer rather than this one.