title: SwiftUI: observe @Environment property changes
body: <p>I was trying to use the SwiftUI <code>@Environment</code> property wrapper, but I can't manage to make it work as I expected. Please, help me understanding what I'm doing wrong. </p>
  
  <p>As an example I have an object that produces an integer once per second:</p>
  
  <pre><code>class IntGenerator: ObservableObject {
      @Published var newValue = 0 {
          didSet {
              print(newValue)
          }
      }
  
      private var toCanc: AnyCancellable?
  
      init() {
          toCanc = Timer.TimerPublisher(interval: 1, runLoop: .main, mode: .default)
              .autoconnect()
              .map { _ in Int.random(in: 0..&lt;1000) }
              .assign(to: \.newValue, on: self)
      }
  }
  </code></pre>
  
  <p>This object works as expected since I can see all the integers generated on the console log. Now, let's say we want this object to be an environment object accessible from all over the app and from whoever. Let's create the related environment key:</p>
  
  <pre><code>struct IntGeneratorKey: EnvironmentKey {
      static let defaultValue = IntGenerator()
  }
  
  extension EnvironmentValues {
      var intGenerator: IntGenerator {
          get {
              return self[IntGeneratorKey.self]
          }
          set {
              self[IntGeneratorKey.self] = newValue
          }
      }
  }
  </code></pre>
  
  <p>Now I can access this object like this (for example from a view):</p>
  
  <pre><code>struct TestView: View {
      @Environment(\.intGenerator) var intGenerator: IntGenerator
  
      var body: some View {
          Text("\(intGenerator.newValue)")
      }
  }
  </code></pre>
  
  <p>Unfortunately, despite the <code>newValue</code> being a <code>@Published</code> property I'm not receiving any update on that property and the <code>Text</code> always shows 0. I'm sure I'm missing something here, what's going on? Thanks.</p>