0

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.

Robert Kang
  • 568
  • 5
  • 19

2 Answers2

1

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.

Robert Kang
  • 568
  • 5
  • 19
0

The error has to do with your managed object model; it's not related to your bindings or table view. If it happens when you run the app (vs. when you try to open a document) it's probably during restoration of autosaved documents.

Try deleting anything related from ~/Library/Autosave Information and seeing if that fixes the initial problem.

paulmelnikow
  • 16,895
  • 8
  • 63
  • 114
  • When I learned these I worked through the Table View Programming Guide and the Core Data Programming Guide. Each has a lot of important detail but neither is the tutorial you're looking for. – paulmelnikow Jun 12 '12 at 20:05
  • Thanks noa. I tried your suggestion, but problem remains the same. To avoid confusion, I removed all the bindings I set up for the table view. The app now only binds CoreData with the NSArrayController. And for the bindings on NSArrayController, I set the model key path to "managedObjectContext", which binds to the instance in appDelegate. – Robert Kang Jun 12 '12 at 20:11
  • And not sure if it matters, but I used Restkit in this project. Initialized with objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"test.sqlite"]; in appDelegate.m – Robert Kang Jun 12 '12 at 20:12
  • Probably that's where the error originates. I'm only barely familiar with RestKit, but try deleting that file. The docs say it's in "the app's Documents directory." – paulmelnikow Jun 12 '12 at 20:56