I am trying to use environmentObject
in a watchOS6 app to bind my data model to my view.
I have created a simple, stand-alone Watch app in Xcode 11.
For anyone like Brett (in the comments) who was getting
"Property 'body' with type 'AnyView' cannot override a property with type 'ContentView'"
I got the same error because I hadn't replaced the return value and wrapped the ContentView being returned.
ie. this is what my first attempt looked like.. notice the
WKHostingController
that should be
WKHostingController
class HostingController : WKHostingController {
override var body: AnyView {
return AnyView(ContentView().environmentObject(DataModel()))
}
}