Question

I want to keep several NSPopUpButtons synchronised with the same model object. I'm just getting familiar with bindings and have implemented the following scheme.

Controllers

Is this a terrible idea?

Here each NSPopUpButton has their own NSArrayController. Each NSArrayController gets their content from the same NSMutableArray data source in my model layer.

I have noticed some strange problems when adding and removing objects to the model array (the array of animals in the example above) and was wondering how viable this approach is or whether there is a better way to keep several views in sync with the same model?

Was it helpful?

Solution

You should be fine doing this, as long as you keep your changes to the model in the main thread.

Each NSArrayController will listen for KVO notifications from your NSMutableArray and will update themselves accordingly.

If you change the array through one of the NSArrayController it will update your NSMutableArray, which again will trigger a KVO notification that will be caught by the other two NSArrayControllers.

It is important that you update your NSMutableArray in a KVO compliant manner. Namely you should be using the array proxy returned by mutableArrayValueForKey:

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