1

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?

Daniel Farrell
  • 9,316
  • 8
  • 39
  • 62

1 Answers1

1

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:

pfandrade
  • 2,359
  • 15
  • 25
  • I was not updating with -mutableArrayValueForKey:, I was simply picking one of the array controllers and adding/removing objects. I will try and deal with the model directly and see if that helps. – Daniel Farrell Feb 14 '14 at 16:18