class ExtensionDelegate: NSObject, WKExtensionDelegate {
let storeContainer = StoreContainer()
func applicationDidEnterBackground() {
storeContainer.save()
}
}
Reference that in HostingController. Note that we need to change from generic MainView to WKHostingController<AnyView> as environmentObject returns View protocol
In theory, the environment object will be propagated down the view hierarchy, but in practice it throws error. So a workaround now is to just pass that environment object down manually
Fatal error: No ObservableObject of type SomeType found
A View.environmentObject(_:) for StoreContainer.Type may be missing as an ancestor of this view
"In theory, the environment object will be propagated down the view hierarchy, but in practice it throws error." This seems to be fixed. Xcode Version 11.2.1 (11B53)
Declare top dependencies in ExtensionDelegate
Reference that in
HostingController
. Note that we need to change from genericMainView
toWKHostingController<AnyView>
asenvironmentObject
returnsView
protocolIn theory, the environment object will be propagated down the view hierarchy, but in practice it throws error. So a workaround now is to just pass that environment object down manually