title: How can I trigger an action when a swiftUI toggle() is toggled?
body: <p>In my SwiftUI view I have to trigger an action when a Toggle() changes its state. The toggle itself only takes a Binding.
  I therefore tried to trigger the action in the didSet of the @State variable. But the didSet never gets called.</p>
  
  <p>Is there any (other) way to trigger an action? Or any way to observe the value change of a @State variable?</p>
  
  <p>My code looks like this:</p>
  
  <pre class="lang-swift prettyprint-override"><code>struct PWSDetailView : View {
  
      @ObjectBinding var station: PWS
      @State var isDisplayed: Bool = false {
          didSet {
              if isDisplayed != station.isDisplayed {
                  PWSStore.shared.toggleIsDisplayed(station)
              }
          }
      }
  
      var body: some View {
              VStack {
                  ZStack(alignment: .leading) {
                      Rectangle()
                          .frame(width: UIScreen.main.bounds.width, height: 50)
                          .foregroundColor(Color.lokalZeroBlue)
                      Text(station.displayName)
                          .font(.title)
                          .foregroundColor(Color.white)
                          .padding(.leading)
                  }
  
                  MapView(latitude: station.latitude, longitude: station.longitude, span: 0.05)
                      .frame(height: UIScreen.main.bounds.height / 3)
                      .padding(.top, -8)
  
                  Form {
                      Toggle(isOn: $isDisplayed)
                      { Text("Wetterstation anzeigen") }
                  }
  
                  Spacer()
              }.colorScheme(.dark)
      }
  }
  </code></pre>
  
  <p>The desired behaviour would be that the action "PWSStore.shared.toggleIsDisplayed(station)" is triggered when the Toggle() changes its state.</p>