Is anyone aware of the following bug on mac os x regarding EnvironmentObjects?
I properly inject the environment object at the top of my view hiearchy. However, this is while creating a new window, so the code looks something like this:
let window = NSWindow(...) let dch = DocumentCanvasHolder() let contentView = ContentView().environmentObject(dch) window.contentView = NSHostingView(rootView: contentView)
This causes a new window to appear on the screen, with the content. Most of the time, this works.
But sometimes, after doing this, while the ContentView() view is putting together its children, one of the children views (always the same one in fact) will crash with the dreaded:
Fatal error: No ObservableObject of type DocumentCanvasHolder found. A View.environmentObject(_:) for DocumentCanvasHolder may be missing
Now, I know I'm doing it right, because 90% of the time, I don't get this, and the view trying to reference an
@EnvironmentObject of type
DocumentCanvasHolder is found. But about 10% of the time, this just fails. No pattern to it.
Is there some defect with EnvironmentObject's on mac os x that anybody is aware of?