so, swift has a simplified but way more efficient setter/getter function workflow than cocoa does. And the way I read it
if you have an array property, and you write a setter:
var anArray : [objs] {
set(newArray){
}
...
then your setter function is called when the array gets an entirely new value:
anArray = [obj01, obj02]
I think I did some tests, which showed that the setter is also called when you append or remove a value from the array:
anarray.append(newObj)
but that was a long time ago, and I'm not certain that it was even supposed to do that.
my question is: is there a setter/getter that I can override that ONLY gets called when my array has been appended, or a value removed? one in which the incoming value is the change, and not the entire array? or am I missing something fundamental? I swear up and down that I have read and re-read the docs.
why? well, when I add a new object to a particular array, I need to add some supporting objects to another array. I could easily write a method, and require the use of that method. But it would be nice to be able to leverage the power of swift in this instance.
The answer to your question is : NO.
In Swift, Array is a value type, so any modifications to a single element (append, remove, replace,...) would invoke setter, when you made the property as computed, as well as the entire array replacement.
To achieve your goal, using KVO is the best way I think, but it's not the power of swift, but the power of Objective-C runtime.
Addition: if you can easily write the method, it may be easier than using KVO.