title: SwiftUI EnvironmentObject out of sync with View
body: <p>To give a simple example of what I'm doing I have an environment object:</p>
  <pre class="lang-swift prettyprint-override"><code>class ViewModel: ObservableObject {
     @Published var x: CGFloat = 0
     @Published var y: CGFloat = 0
  }
  </code></pre>
  <p>A view that's watching those numbers to adjust it's offset:</p>
  <pre class="lang-swift prettyprint-override"><code>struct PrimaryView: View {
      @EnvironmentObject var model: ViewModel
  
  // inside the view struct
  
      SomeView()
          .offset(x: model.x, y: model.y)
  }
  </code></pre>
  <p>And another view that's responsible for changing  those numbers:</p>
  <pre class="lang-swift prettyprint-override"><code>struct ChangeView: View {
      @EnvironmentObject var model: ViewModel
  
  // inside the view
  
      Button(action: {
                 switch directionCondition {
                      case .up:
                          model.y += 10
                      case .down:
                          model.y -= 10
                      case .left:
                          model.x += 10
                      case .right:
                          model.x -= 10
  
             }) // end button here for brevity
  
  </code></pre>
  <p>When my app loads sometimes it works perfectly and other times the press will not fire initially at all then when you tap it again it will trigger.</p>
  <p>Here's what I've tried so far. I put the mutations in the view model and only called the functions that caused the changes in the <code>ChangeView</code>. I dispatched those changes asynchronously using <code>DispatchQueue</code>. I removed the switch statement from the button and did those changes manually. And finally I put the mutations back in the view to see if that made a difference in the performance.</p>
  <p>None of this worked so I'm starting to feel like this is potentially a bug on apple's part but I could also be doing something entirely incorrect. Also yes the environment object is correctly attached to the app root in <code>App.Swift</code>.</p>