In my last question, I asked how to write setter for a subscript of a computed property in Swift. I think my question was not substantial enough to be understood. The answer giv
What you're not understanding is that an ordinary setter is the shorthand you are looking for. If an object has an array property and someone sets into that array, the setter is called.
For example:
class Thing {
var arr : [Int] = [1, 2, 3] {
didSet {
println("I saw that")
}
}
}
var t = Thing()
t.arr[1] = 100 // "I saw that"
So all you have to do is use didSet
to compare the new value to the old value and respond however you like to the change.