
From a developer's perspective, the NSManagedObjectContext class is the workhorse of the Core Data framework. The managed object context creates, reads, updates, and deletes model objects. The managed object context is the object you interact with most. In the above diagram, you can see that every managed object context has a reference to the application's persistent store coordinator. The managed object context receives the model objects through a persistent store coordinator. Each managed object context manages a collection of model objects, instances of the NSManagedObject class. Managed Object ContextĪ Core Data application has one or more managed object contexts. For now, remember that the managed object model is an instance of the NSManagedObjectModel class and represents the data model of the Core Data application. We explore the data model in more detail later. An entity can have attributes and relationships, which make up the data model of the application. The data schema is nothing more than a collection of entities. The data model is represented by a file in the application bundle that contains the data schema of the application.

The above diagram shows that the managed object model is connected to the data model. The instance represents the data model of the Core Data application. A typical Core Data application has one instance of the NSManagedObjectModel class. The managed object model is an instance of the NSManagedObjectModel class. We use this diagram as a guideline in this tutorial. The following diagram shows the relationships of these objects.


The star players of the Core Data framework are the persistent store coordinator, the managed object model, and the managed object context. As I mentioned earlier, it's key that you understand how the various classes that make Core Data tick play together. Now that you have an idea of what Core Data is, it's time to zoom in on the building blocks of the Core Data framework. Let's first discuss how Core Data works by exploring the Core Data stack. What Core Data is and isn't becomes clear along the way. Don't get too attached to this definition, though. While Core Data does quite a bit more, it's important that you understand the objective of the framework. The definition I often use is short and simple.Ĭore Data is a framework for managing and persisting an object graph. It's hard to define Core Data because it behaves like a database while Apple clearly states that it isn't a database. What Is Core Data?Īsking someone to define Core Data is a bit of a trick question. We start by exploring the Core Data stack and discussing the key players of the framework. In this tutorial, I explain what you need to know about Core Data to learn the basics of this amazing framework. We cover this extensively in Mastering Core Data With Swift. Don't skip this step.īefore you start using the framework in a project, it's important to take the time to become familiar with the Core Data stack and the framework's key classes. To get a good grasp of Core Data, a solid foundation is instrumental. First Things Firstĭevelopers new to Core Data are often overwhelmed by the framework's terminology and the plethora of classes defined by the framework. Apple continues to invest in Core Data, adding features, increasing performance, and improving reliability with every iteration of the framework. It's been around for more than a decade and it's used in thousands of iOS and macOS applications. On iOS, the framework has been available since iPhone OS 3.0.Ĭore Data has earned its stripes as a reliable and performant persistence layer.

#Xcode 9 development and best database for mac os mac os x
It was introduced in 2005, alongside the release of Mac OS X Tiger. Core Data is Apple's framework for managing and persisting an object graph. If you dipped your toe in iOS or macOS development, then you've probably heard about Core Data.
