title: SwiftUI send button tap to subview
body: <p>I have a few views that contain the same button with some different content. Because of this I made a <code>ContainerView</code> that houses the shared <code>Button</code> layout, and has room for a generic <code>ContentView</code>.</p>
  
  <p>I want the <code>ContentView</code> to respond when the <code>ContainerView</code> button is tapped. </p>
  
  <p>Using UIKit, I would hold a reference to the <code>ContentView</code> in the <code>ContainerView</code> and call a function on it when the button was hit. However, because SwiftUI has all the views as structs, the <code>contentView</code> is copied when put into the <code>ContainerView</code>'s <code>body</code>. Thus the reference and the shown <code>ContentView</code> are different &amp; I cannot send the subview a message.</p>
  
  <p>Code:</p>
  
  <pre class="lang-swift prettyprint-override"><code>struct ContainerView: View {
      let contentView = ContentView()
  
      var body: some View {
          Group {
              /// When this button is tapped, I would like to send a message to the `ContentView`.
              Button(action: self.reset, label: { Text("RESET") })
              /// Unfortunately, this seemes to send a copy of the `contentView`. So I am unable to send the
              /// corrent struct a message.
              ///
              /// How can I send a subview a message from the superview?
              self.contentView
          }
      }
  
      func reset() {
          self.contentView.reset()
      }
  }
  
  struct ContentView: View {
      @State private var count: Int = 0
  
      var body: some View {
          Group {
              Text("Count: \(self.count)")
              Button(action: self.increment, label: { Text("Increment") })
          }
      }
  
      func increment() {
          self.count += 1
      }
  
      /// When this is called from the `ContainerView`, it is accessing a different ContentView 
      /// struct than is being displayed.
      func reset() {
          self.count = 0
      }
  }
  </code></pre>
  
  <p>So the question is: how can I send a message to &amp; run some code in the <code>ContentView</code> when a button in the <code>ContainerView</code> is tapped?</p>