4
votes

From apple CoreData framework docs,

Managed object model: A model allows Core Data to map from records in a persistent store to managed objects that you use in your application. Refer here.

Persistent object store: A persistent object store maps between objects in your application and records in a persistent store. Refer here.

From these description, both are meaning the same that is mapping persistent store records with managed objects.

I would like to know what is the unique difference between Managed object model and Persistent object store.

2

2 Answers

4
votes

The managed object model is an instance of NSManagedObjectModel and describes the schema used in your Core Data application. It is loaded from the model file which contains all the entity descriptions with their attributes and relationships that you defined in the Core Data Model inspector. So the model describes your objects.

The persistent object store is an instance of NSPersistentStore, which manages the transactions to and from a persistent store, which is the repository where the actual data is stored. In many cases, the persistent store is a SQLite file, but it can also be an XML file, a binary file or a "in-memory" store for temporary data.

The persistent store coordinator uses both: The NSManagedObjectModel and (one or more) NSPersistentStores, to load managed objects from the store into the application and to write changed objects back into the store.

1
votes

Regardless your question passed quite long, but it remains a clear concern which may help others to clarify & deep diving the topic. So, not go too far from Martin's answer, but take further explanation for you:

  • Yes, Persistent Store and Persistent Object Store are totally 2 different matters

    • But No, Persistent Object Store IS NOT an instance of NSPersistentStore. Just somehow like Persistent Store, it's ONE file consisting of Classes which automatically declare by Xcode the paths / relations between Objects / Instances in the application and the bunches / blocks of code within the Persistent Store. Think of it like a file of hyperlinks (although it's much more complicated than that)
  • Let think of Persistent Store as "DataFile.xml / DataFile.sqlite / DataFile.customExtension, etc.". Because they are files, so all the records are stored as Script, Binary and so on. For example: < entityname > Transaction < /entity > OR < currency >USD< /currency > (No Space - Sorry that the website does not allow to add these (<...>))

    • The compilers (in this case XCode) can access, read and write to Persistent Store (files), but definitely require 2 things: (1) "translator" to decode from SCRIPT to OBJECT following the "instruction" of the "blueprint" Managed Object Model, (2) Like Managed Object Context is a temp place for Xcode working with Managed Objects before storing - Persistent Object Store play the similar role, but with SCRIPT & MODEL (provided by Managed Object Model) instead --> SO, THEY ARE THE ROLE OF PERSISTENT OBJECT STORE.

In practical programming, you don't even need to think of Persistent Object Store. It's an automatic process all which XCode takes. It's an abstract computing process rather than a specific concept or a specific stake (within Core Data Stack)

Referring to Apple's guide on Core Data (2011, Oct - quite old but remain active) https://developer.apple.com/library/prerelease/content/documentation/DataManagement/Devpedia-CoreData/persistentObjectStore.html#//apple_ref/doc/uid/TP40010398-CH31-SW1

--> "You don’t create a persistent object store directly. Instead, Core Data creates a store of the appropriate type for you when you send an addPersistentStoreWithType:configuration:URL:options:error: message to a persistent store coordinator."

Hope this helpful to you.