title: Observe changes in any property of any member of an array
body: <p>I have an array which stores objects of a class:</p>
  
  <pre><code>class Apple {
  
      var color = "Red"
  
  }
  
  let myApple = Apple()
  
  var apples = [Apple]()
  
  apples.append(myApple)
  
  // Func should be called here
  myApple.color = "Blue"
  
  let otherApple = Apple()
  
  // Func should not be called here, 
  // because otherApple is not a member of apples array
  otherApple.color = "Green"
  </code></pre>
  
  <p>I want to run a function when any property of any member of "apples" array has changed. When calling this function, I need to pass the item of the array whose property is changed as a parameter. </p>
  
  <p>I thought of using <code>didSet</code> on color property, but in that case function is called when otherApple's property is changed too. This is not what I want. I only want to run the function when a property of a member of the array has changed. If it is not a member, the function should not run.</p>
  
  <p>Using <code>didSet</code>, running the function in any case, and checking membership in the beginning of the function might be an idea but I feel this is not a good way.</p>
  
  <p>How can I properly achieve this with Swift?</p>
  
  <p>Edit: Apple's guide for <a href="https://developer.apple.com/documentation/swift/cocoa_design_patterns/using_key-value_observing_in_swift" rel="nofollow noreferrer">Using Key-Value Observing in Swift</a></p>