This tutorial takes you through the steps of building a very basic Core Data–based command line utility. The goal is to illustrate the creation of a Core Data application entirely in code.
The task goal of this tutorial is to create a low-level Core Data-based utility. It simply records the date on which the utility is run, and its process ID, and prints the run history to the output. The tutorial shows the creation of a Core Data application entirely in code, including all aspects of the Core Data stack, instantiation of managed objects, and fetching—all without the distraction of a user interface—it even shows the creation of a model in code.
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.
Important: This tutorial is not intended for novice Cocoa developers. You must already be familiar with basic Cocoa development tools and techniques. This document does not repeat fundamental Cocoa programming concepts, nor does it provide explicit instructions for common operations in Xcode.
You should already be familiar with the fundamental Core Data architecture as described in “Core Data Basics” in Core Data Programming Guide. This tutorial is intended to reinforce the ideas explained in that article.
If you are developing applications for iOS, you should work through Core Data Tutorial for iOS before attempting this tutorial.
“Overview of the Tutorial” describes the utility you will create, and the task constraints.
“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.
Core Data Programming Guide describes functionality provided by the Core Data framework from a high-level overview to in-depth descriptions.
Last updated: 2010-05-24