title: SwiftUI Combine: Nested Observed-Objects
body: <p>What is the best approach to have swiftUI still update based on nested observed objects?</p>
  <p>The following example shows what I mean with nested observed objects. The balls array of the ball manager is a published property that contains an array of observable objects, each with a published property itself (the color string).</p>
  <p>Unfortunately, when tapping one of the balls it dos not update the balls name, nor does it receive an update. So I might have messed up how combine was ment to work in that case?</p>
  <pre><code>import SwiftUI
  
  class Ball: Identifiable, ObservableObject {
      let id: UUID
      @Published var color: String
      init(ofColor color: String) {
          self.id = UUID()
         self.color = color
      }
  }
  
  class BallManager: ObservableObject {
      @Published var balls: [Ball]
      init() {
          self.balls = []
      }
  }
  
  struct Arena: View {
     @StateObject var bm = BallManager()
  
      var body: some View {
          VStack(spacing: 20) {
              ForEach(bm.balls) { ball in
                  Text(ball.color)
                      .onTapGesture {
                          changeBall(ball)
                      }
              }
          }
          .onAppear(perform: createBalls)
          .onReceive(bm.$balls, perform: {
              print(&quot;ball update: \($0)&quot;)
          })
      }
      
      func createBalls() {
          for i in 1..&lt;4 {
              bm.balls.append(Ball(ofColor: &quot;c\(i)&quot;))
          }
      }
      
      func changeBall(_ ball: Ball) {
          ball.color = &quot;cx&quot;
      }
  }
  </code></pre>