title: How can I observe a specific element with Swift collection types using property observers?
body: <p>Inspired when answering the question of <a href="https://stackoverflow.com/questions/41118406/how-do-i-know-if-a-value-of-an-element-inside-an-array-was-changed">How do I know if a value of an element inside an array was changed?</a>, The answer was using a <em>Property Observer</em> for checking if an array has been modified.</p>
  
  <p>However, How can I determine what is/are the updated element(s) in a collection type in a property observer? For example:</p>
  
  <pre><code>class MyClass {
      var strings: [String] = ["hello", "world", "!"] {
          didSet(modifiedStrings) {
              print("strings array has been modified!!:")
              print(modifiedStrings)
          }
      }
  }
  
  let myClass = MyClass()
  myClass.strings.append("a string")
  myClass.strings[0] = "Hello"
  myClass.strings.removeLast()
  </code></pre>
  
  <p>Note that the <code>didSet</code> code has been called for each of adding, updating or deletion operation, but how can I exactly know what are the effected elements? is there even a way to achive this by decalring <code>strings</code> array as a <em>Property Observer</em>?</p>
  
  <p>I am asking about all collection types in Swift because I assume that it should be the same behavior for all of them, it is about the observing.</p>
  
  <p>Thanks.</p>