Question

I want to execute a method (or selector) every time a new object has been added to my array controller.

I guess it can be somehow done with key-value observing, but I don't exactly know how.

Can someone give me example code?

Was it helpful?

Solution

Add yourself as an observer for the array controller's arrangedObjects. When an object is added or removed in its content array, it will add or remove it at the appropriate position in that array, and it will notify any observers with the change.

The dictionary describing the change will contain keys that describe exactly what happened to the array, so you can find the object that was added without having to look at any others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top