What Is Core Data?

In the simplest terms, Core Data is an object graph that can be persisted to disk. But just like describing a man as a “bag of mostly water,” that description hardly does Core Data justice. If you’ve worked with Interface Builder (specifically on OS X), you know that it effectively removes a third of the coding from the Model-View-Controller (MVC) design pattern. With Interface Builder, developers don’t need to spend countless hours writing and rewriting their user interface to make sure that it’s pixel perfect. Instead, they simply drag and drop the elements in the IDE, bind them together, and call it done.

Of course, the problem with Interface Builder is that we still need to code the other two parts! Both the controller and the model need to be developed in code and made to work with the interface we just designed. That’s where Core Data comes in. In a nutshell, Core Data deals with a third of that MVC design: Core Data is the model.

It’s a common misconception that Core Data is a database API for Cocoa that allows a Cocoa application to store its data in a database. Although that description is factually accurate, Core Data does a lot more. It serves as the entire model layer. It’s not just the persistence on disk; it’s also all the objects in memory that we normally consider to be data objects. If you have experience working with Java, C#, or some other object-oriented language, you know that the data objects take a lot of time to write and that they’re generally very repetitive in nature. Core Data eliminates most, if not all, of that boilerplate code for us and lets us focus on the business logic, or the controller layer, of our application. It does this with an interface that’s as easy to use as Interface Builder.

In addition to ease of use, Core Data is highly flexible. If we need to step in and change the functionality of some portion of the data model, we can. From how a value is handled when it’s being accessed to how data is migrated from one persistent store to another, we can choose how little or how much we want to code ourselves and how much we want Core Data to do for us.

When you start to learn Core Data, it’s best to think in terms of objects. Core Data is a framework designed to manage your data and data object graph. As a secondary function, it will persist that data to disk. However, its primary function is to manage the objects.