title: Swiftui @EnvironmentObject update in View
body: <p>I am using an @EnvironmentObject (which is the ViewModel) and I have a demoData() function.</p>
  <p>When I press it the data does change but my View is not updated.</p>
  <p>How do I get the data to change in the View?</p>
  <p>Thank you.</p>
  <p>The view information:</p>
  <pre><code>import Combine
  import SwiftUI
  
  struct MainView: View {
   
      @EnvironmentObject var entry:EntryViewModel
  
       var body: some View {
  
           TextField(&quot;Beg Value&quot;, text: self.$entry.data.beg)
           TextField(&quot;Beg Value&quot;, text: self.$entry.data.end)
  
           Button(action: { self.entry.demoData() }) { Text(&quot;Demo Data&quot;) }
  
      }
  }
  </code></pre>
  <p>ViewModel:</p>
  <pre><code>class EntryViewModel: ObservableObject {
   
      @Published  var data:EntryData = EntryData()
  
      func demoData() {
       
          var x = Int.random(in: 100000..&lt;120000)
          x = Int((Double(x)/100).rounded()*100)
          data.beg = x.withCommas()
      
          x = Int.random(in: 100000..&lt;120000)
         x = Int((Double(x)/100).rounded()*100)
         data.end = x.withCommas()
      
  }
  </code></pre>
  <p>Model:</p>
  <pre><code> EntryData:ObservableObject {
  
      @Published var beg:String = &quot;&quot;
      @Published var end:String = &quot;&quot;
  
  }
  </code></pre>