title: Using environmentObject in watchOS
body: <p>I am trying to use <code>environmentObject</code> in a watchOS6 app to bind my data model to my view.</p>
  
  <p>I have created a simple, stand-alone Watch app in Xcode 11.</p>
  
  <p>I created a new <code>DataModel</code> class</p>
  
  <pre><code>import Combine
  import Foundation
  import SwiftUI
  
  final class DataModel: BindableObject {
  
      let didChange = PassthroughSubject&lt;DataModel,Never&gt;()
  
      var aString: String = "" {
          didSet {
              didChange.send(self)
          }
      }
  
  }
  </code></pre>
  
  <p>In my <code>ContentView</code> struct I bind this class using <code>@EnvironmentObject</code> - </p>
  
  <pre><code>struct ContentView : View {
  
      @EnvironmentObject private var dataModel: DataModel
  
      var body: some View {
          Text($dataModel.aString.value)
      }
  }
  </code></pre>
  
  <p>Finally, I attempt to inject an instance of the <code>DataModel</code> into the environment in the <code>HostingController</code> class -</p>
  
  <pre><code>class HostingController : WKHostingController&lt;ContentView&gt; {
      override var body: ContentView {
          return ContentView().environmentObject(DataModel())
      }
  }
  </code></pre>
  
  <p>But, I get an error:</p>
  
  <pre><code>Cannot convert return expression of type '_ModifiedContent&lt;ContentView, _EnvironmentKeyWritingModifier&lt;DataModel?&gt;&gt;' to return type 'ContentView'
  </code></pre>
  
  <p>The error is because the <code>WKHostingController</code> is a generic that needs a concrete type - <code>WKHostingController&lt;ContentView&gt;</code> in this case.  </p>
  
  <p>A similar approach works perfectly with <code>UIHostingController</code> in an iOS app because <code>UIHostingController</code> isn't a generic class.</p>
  
  <p>Is there some other way to inject the environment to a watchOS view?</p>