Initializer

init(_:)

Creates a UIKit app delegate adaptor.

Declaration 宣言

init(_ delegateType: DelegateType.Type = DelegateType.self)

Parameters パラメータ

delegateType

The type of application delegate that you define in your app, which conforms to the UIApplicationDelegate protocol.

Discussion 議論

Call this initializer indirectly by creating a property with the UIApplicationDelegateAdaptor property wrapper from inside your App declaration:


@main
struct MyApp: App {
    @UIApplicationDelegateAdaptor 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.

See Also 参照

Creating a Delegate Adaptor