How to tell SwiftUI views to bind to more than one nested ObservableObject : <p>I have two classes nested in another class, which is an observable object in a SwiftUI view. Even though properties in the nested classes are declared as @Published, their values (when they change) do not update in the main view.</p>

<p>A similar question has been asked here, and I could use it to get it to work for one of the two subclasses, but not both.</p>

<p><a href="https://stackoverflow.com/questions/58406287/how-to-tell-swiftui-views-to-bind-to-nested-observableobjects">How to tell SwiftUI views to bind to nested ObservableObjects</a></p>

<p>This is the model:</p>

<pre><code>class Submodel1: ObservableObject {
  @Published var count = 0
}

class Submodel2: ObservableObject {
  @Published var count = 0
}

class Model: ObservableObject {
  @Published var submodel1: Submodel1 = Submodel1()
  @Published var submodel2: Submodel2 = Submodel2()
}
</code></pre>

<p>And this is the main view:</p>

<pre><code>struct ContentView: View {
  @ObservedObject var model: Model = Model()

  var body: some View {
    VStack {
      Text("Count: \(model.submodel1.count)")
        .onTapGesture {
          self.model.submodel1.count += 1
        }
      Text("Count: \(model.submodel2.count)")
        .onTapGesture {
          self.model.submodel2.count += 1
        }
    }
  }
}
</code></pre>

<p>Adding this to the model class (see previous Stackoverflow question) works for updating on submodel1 changes, but not both:</p>

<pre><code>  var anyCancellable: AnyCancellable? = nil
  init() {
      anyCancellable = submodel1.objectWillChange.sink { (_) in
          self.objectWillChange.send()
      }
   }
</code></pre>

<p>What I'm looking for is some way to pass on changes of both the submodel1 and submodel2 to my view.</p>
