Home Cocoa Snippets Cocoa Notes
Cocoa Notes


Observing Arrays
Cocoa bindings allows you to link e.g. a NSTableView to a model data structure. When I want to implement this capability in my custom view the view needs to use key-value coding (KVC) and key-value observing (KVO). KVC is used to modify properties of the model the view is linked to and KVO will keep the view informed about changes of the model.
Things start to become somewhat more complicated, when the view should observe some properties of a "bunch" of objects – so I tried to put this functionality in a generic helper class.

Read more...
 
Observing Arrays for Undo 'Recording'

The previous snippet presented a helper class that handles observing element properties of an array – or "ordered to-many relation" to be correct. That first helper class was targeted towards view update notifications for triggering a redraw. Now here is an extended version that automatically records undo information for each observed change. This is very useful if the model is not core data based and is changed by multiple sources. It may also be useful if one change may trigger other changes which are harder to track for undo recording.

Read more...