This part of the tutorial guides you through creating the CDCLI project.
Core Data is integrated into the Cocoa framework, so any Cocoa or Foundation application can use it. The CDCLI program you’ll build is Foundation Tool that uses Core Data and garbage collection.
Follow these steps to create the initial project:
Choose New Project from the File menu.
Select Foundation Tool in Xcode’s project Assistant window (from the Command Line Utility section), and click the Next button.
Enter the project name (for example, “CDCLI”) and a destination folder for the project.
main function is hereafter referred to as “the main source file.”Link the Core Data framework to the project.
In Xcode, you can double-click the CDCLI Target to open the Target Info pane. In the General tab you can then add CoreData.framework to the list of Linked Libraries. See Files in Projects in Xcode Project Management Guide for details.
Add an import statement to the main source file (#import <CoreData/CoreData.h>).
Remove the references to autorelease pools; add a function call to start the garbage collector; and change the project build settings to use garbage collection:
In the main source file, remove the lines that create and drain the autorelease pool:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
[pool drain]; |
At the beginning of the main source file, add a function call to start the garbage collector:
objc_startCollectorThread(); |
In the project’s Build settings, change the garbage collection setting to Required (see “Enabling Garbage Collection” in Garbage Collection Programming Guide).
You created a very simple Foundation Tool project and added the Core Data framework. There is no need to use the Application Kit when using Core Data. It is not even necessary to use the Xcode data modeling tool. In the next chapter you will create the model entirely in code. Using the modeling tool does, however, typically save you a lot of time and effort.
Last updated: 2009-03-04