title: Unable to update/modify SwiftUI View's @state var
body: <p>I'm unable to update the ExampleView's <code>message</code> var even though I can see <code>updateMessage()</code> is being called. Here is my simplified/convoluted SwiftUI example of Playground code that isn't working. The <code>message</code> var does not get updated when called in <code>updateMessage()</code>. As a result, the UI <code>Text()</code> is not updated either.</p>
  
  <p>Why is the @State var <code>message</code> not updating? What is the correct way to update it?</p>
  
  <pre><code>import SwiftUI
  import PlaygroundSupport
  
  struct ContentView: View {
      let coloredLabel = ExampleView()
  
      var body: some View {
          VStack {
              coloredLabel
                  .foregroundColor(Color.red)
                  .padding()
              Button(action: {
                  self.coloredLabel.updateMessage()
              }) {
                  Text("Press me")
              }
  
          }
      }
  }
  
  struct ExampleView: View {
      @State private var message: String = "Hello"
  
      var body: some View {
          Text(self.message)
      }
  
      func updateMessage() {
          print("updateMessage ran") // this prints
          self.message = "Updated"
      }
  }
  
  PlaygroundPage.current.setLiveView(ContentView())
  </code></pre>