CoreData ArrayControllers in Cocoa storyboards

I am developing a Mac OS port for an iOS app and am facing an issue with NSManagedObjectContexts when using NSArrayControllers in a storyboard based Cocoa app.

This is sort of the next question: Storyboard with TabViewController in OS X app - Master data array controllers in each scene?

I have some ViewControllers presented as a TabBarController showing the same CoreData objects. They are loaded through NSArrayControllers that are connected to the InterfaceBuilder.

From my existing knowledge, there was no problem getting data on screens. Even editing and saving to CoreData works. But I realized that each Storyboard scene got its own instance of NSArrayControllers and each its own NSManagedObjectContext. When changing and saving data in one screen, it does not update on other screens, they are all linked through IB bindings and work in all other cases. They just show the data, they were loaded initially and are not automatically updated.

I think the problem is that the modified data from context A is not merged (or synchronized) with other contexts of other screens.

What's the best way to do this? Should I use NSManagedObjectContextDidSaveNotification for this?

This would mean that I would have to write a lot of code to manually merge changes from one context to all other NSManagedContexts. It smells bad to me. I think there must be a much simpler way that I am not aware of and cannot find out about.

If you have a hint of me, just keep me in the right direction. Thanks for that already.

+3


source to share


1 answer


Problem solved, I made a thumb error with Cocoa Bindings: I just dragged the object into the storyboard on each scene and set it to the AppDelegate. I just created some AppDelegates with this very bad idea! I fixed this by referencing the AppDelegate via properties on my ViewControllers and it now works as it should. IB just has its own little facets where you need to be fully aware of what is happening.



0


source







All Articles