![]() | Core Data and Document-Based apps / NSPersistentDocument |
|
23 Nov 2012, 22:39
Mel Torme (5 posts) |
First of all, I’m incredibly sorry if this has already been addressed elsewhere, but I’ve been reading through the book and these forums and I haven’t found a decent solution yet. How do I work with Core Data in a Document-based application in Mac OS X? What parts of the Core Data structure are automatically created when using a Document-based app and which do I need to initialize? I assume I still need to establish a Persistent Store, but how do I reference it? Is it automatically an SQLite store? Chapter 10 (Dynamic Properties) makes some reference to NSPersistentDocument, but I’m unclear as to how I’m supposed to configure things. What’s the proper way to access the Core Data persistent store from the various classes in my document? Through which chapters should I read in order to gain the best understanding of the proper way to initialize and manipulate Core Data in a document-based Mac OS X app? Thank you in advance for your assistance! |
|
26 Nov 2012, 10:01
Marcus S. Zarra (239 posts) |
This has not been covered in depth because it is not a commonly used feature of OS X/Core Data and because there is not much of a variant. Effectively you use From there you treat it like a normal document. |
|
03 Dec 2012, 20:39
Mel Torme (5 posts) |
Marcus – Thank you for your reply. If you ever decide to change your mind, I believe there’s plenty that can be discussed. Just for starters, consider the following: 2) Why can’t a ManagedObjectContext in a NSPersistentDocument respond to the save: request? ...which may answer… 3) Why can’t a NSPersistentDocument follow your multi-threading recommendations from the book? Any locally-created ManagedObjectContext in an NSOperation, despite being connected to the same persistent store as the main document, returns a fault when attempting to access an entity’s properties. I assume this is because ManagedObjects added by the document are added to the document’s ManagedObjectContext and not persisted to the store. Pardon the pun, but you could totally write the book on NSPersistentDocuments. Especially considering Apple’s NSPersistentDocument tutorial is from 10.4 and is labeled “Not Recommended”. |
| You must be logged in to comment |

