I tried to transfer the example from chapter 9 to a document based application. My setup starts from the “Cocoa Application” template with “Use Core Data” and “Create Document-Based Application” checked.
The application contains a very simple MOM and imports a larger dataset. The import updates in the UI via bindings. Everything is fine, but the UI is not responsive (and i did’t expect it would be responsive).
Now i create a NSOperation to perform the import in the background with its own MOC. And here it comes: Merging takes not place because an exception is thrown:
2011-11-14 22:12:59.950 CoreDataTest[21596:5d03] An uncaught exception was raised 2011-11-14 22:13:00.070 CoreDataTest[21596:5d03] This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation. [Switching to process 21596 thread 0x903] 2011-11-14 22:13:03.093 CoreDataTest[21596:5d03] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.’ terminate called after throwing an instance of ‘NSException’ warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn’t in the frame.
I think that i have to add a persistent store to the coordinator, but i want to do it with the following constraints:
- a new document has no file associated
- a new document is not “dirty”
- while importing data the UI is updated regularly via bindings
- after importing data the document is dirty and has no file associated on disk
- after clicking “Save…” the file chooser rises and the user can choose a filename and location
- after saving the document to the new location the document is clean again
What do you think is the correct design pattern for this kind of application?