Initializer

init(_:)

Creates a WatchKit extension delegate adaptor.

Declaration 宣言

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

Parameters パラメータ

delegateType

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

Discussion 議論

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


@main
struct MyApp: App {
    @WKExtensionDelegateAdaptor private var extensionDelegate: MyExtensionDelegate


    var body: some Scene { ... }
}

SwiftUI initializes the delegate and manages its lifetime, calling upon it to handle extension 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