Issue #467

Declare top dependencies in ExtensionDelegate

class ExtensionDelegate: NSObject, WKExtensionDelegate {
    let storeContainer = StoreContainer()

    func applicationDidEnterBackground() {

Reference that in HostingController. Note that we need to change from generic MainView to WKHostingController<AnyView> as environmentObject returns View protocol

class HostingController: WKHostingController<AnyView> {
    var storeContainer: StoreContainer!

    override func awake(withContext context: Any?) {
        super.awake(withContext: context)
        self.storeContainer = (WKExtension.shared().delegate as! ExtensionDelegate).storeContainer

    override var body: AnyView {
        return AnyView(MainView()

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

struct MainView: View {
    @EnvironmentObject var storeContainer: StoreContainer
    var body: some View {
        VStack {
            List({ AnyService($0) })) { anyService in
                    ItemsView(service: anyService.service)
                        .onDisappear(perform: {
                ) {
                    HStack {
                            .frame(width: 30, height: 30, alignment: .leading)

Updated at 2020-06-26 03:54:01