Search code examples
cocoacore-datatableviewcocoa-bindingsnsarraycontroller

Binding issue between Core Data and NSArrayController


I am trying to set up the binding between Core Data, NSArraycountroller and a NSTableView. To get a NSManagedObjectContext for the NSArrayController. I dragged an NSObject in the IB, and named it after the appDelegate and then set up the binding of objectContext between appDelegate and the arrayController.

However, whenever I tried to run the app. I get this error message:

The error message:

The managed object model version used to open the persistent store is incompatible with
the one that was used to create the persistent store

And then followed by another error message:

Failed to initialize store.

I googled around, most of the people can solve this issue by clean their project or delete the files under ~/Library/Application Support/AppName/.. But I don't have luck with those.

Another thing is that, I desperately want some good tutorial on this topic (CoreData+ArrayController+TableView). Can someone shed some light on this as well? I read through the chapter 11 of the book "Cocoa Programming for Mac OSX 4th version", but didn't find it really helpful.

Thanks.


Solution

  • Finally solved this issue. I think it has to do with Reskit. Reskit has its own managedObjectContext when bundle with CoreData. That's why it keeps telling me the two object model is incompatible. The NSArrayController should be binded to the managedObjectContext in RKManager instead of the one in appDelegate.

    So I put this in the init method of view controller:

    RKObjectManager *objectManager = [RKObjectManager sharedManager];
    currentObjectContext = objectManager.objectStore.managedObjectContextForCurrentThread;
    

    And point the managedObjectContext in the NSArrayController object to the currentObjectContext.