Introduction to Core Data Utility Tutorial

This tutorial takes you through the steps of building a very basic Core Data–based command line utility. The tutorial illustrates how you create from scratch an application that uses Core Data, including all aspects of the Core Data stack, instantiation of managed objects, and fetching—it even shows the creation of a model in code.

The utility is a command-line application that simply records the date on which the utility is run, and its process ID, and prints the run history to the output. Using a command line application reinforces the idea that Core Data is platform-independent and isn’t tied to a particular user interface framework or platform.

The emphasis in this tutorial is on illustrating low-level functionality in Core Data, not on compactness, maintainability, or user friendliness. Although some explanation is given of what happens behind the scenes, it does not give an in-depth analysis of the Core Data infrastructure.

Who Should Read This Document

You will find this tutorial useful if you are using the Core Data framework to create a utility that does not have a user interface or if you want to gain a deeper understanding of the Core Data infrastructure.

If you are developing applications for iOS, you may find it useful to work through Core Data Tutorial for iOS before attempting this tutorial. Core Data Tutorial for iOS describes the architecture of the Core Data stack created by the Xcode templates.

Organization of This Document

“Creating the Project” describes how you create a Foundation Tool project in Xcode, and how you link in Core Data.

“Creating the Managed Object Model” describes how you create the data model for the utility in code.

“The Application Log Directory” illustrates one way to identify and if necessary create a directory in which to save the file for the utility’s persistent store.

“Creating the Core Data Stack” describes how to create and configure the managed object context and the persistent store coordinator in code.

“The Custom Managed Object Class” specifies the Run entity and describes how to implement a custom managed object class.

“Listing Previous Runs” describes how to fetch Run instances from the persistent store.

“Complete Source Listings” shows the complete source code for the project.

See Also

Core Data Programming Guide describes functionality provided by the Core Data framework from a high-level overview to in-depth descriptions.