init(DelegateType .Type)
The type of extension delegate that you define in your app, which conforms to the WKExtension
and Observable
protocols.
Availability 有効性
Technology
init(_ delegateType: DelegateType .Type = DelegateType.self)
DelegateType
inherits NSObject
, DelegateType
conforms to ObservableObject
, and DelegateType
conforms to WKExtensionDelegate
.delegateType
The type of extension delegate that you define in your app, which conforms to the WKExtension
and Observable
protocols.
Call this initializer indirectly by creating a property with the WKExtension
property wrapper from inside your App
declaration:
@main
struct MyApp: App {
private var extensionDelegate: MyExtensionDelegate
var body: some Scene { ... }
}
SwiftUI initializes the delegate and manages its lifetime, calling it as needed to handle extension delegate callbacks.
SwiftUI invokes this method when your extension delegate conforms to the Observable
protocol. In this case, SwiftUI automatically places the delegate in the Environment
. You can access such a delegate from any scene or view in your app using the Environment
property wrapper:
private var appDelegate: MyAppDelegate
If your delegate isn’t an observable object, SwiftUI invokes the init(_:)
initializer rather than this one, and doesn’t put the delegate instance in the environment.
init(DelegateType .Type)