Search code examples
cocoadesign-patternscocoa-bindings

Implementing Cocoa Bindings pattern


I have a class MyImage, that have a NSAffineTransform member transform.

In my AppDelegate a have a NSMutableArray of images.

I have a MyView that draw the images from AppDelegate.images. So it must track changes in AppDelegate.images and redraw the content.

What is the best way to implement this though bindings?


Solution

  • You don't mean bindings, or if you do you have misunderstood how bindings work and what they are for.

    For an explanation read this post - Manual binding in Cocoa

    You need to use KVO to observe the array of images. You need to make sure you add and remove images from the array in a KVC compliant way.