iOS Reference Library Apple Developer
Search

Creating the Project

This part of the tutorial guides you through creating the CDCLI project.

Create a New Project

Core Data is integrated into the Cocoa (and Cocoa Touch) 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.

Create the project

Follow these steps to create the initial project:

  1. Launch Xcode.

  2. Create a project with these characteristics:

    • Platform: Mac OS X

    • Template family: Application

    • Template name: Command Line Tool

    • Type: Foundation

Note: The source file created by the Assistant that contains the main function is hereafter referred to as ‚Äúthe main source file.‚Äù

Link the Core Data framework

  1. Add the Core Data framework to the project’s target. (A Foundation tool does not automatically include the Core Data framework, which is why you need to add it.)

  2. Add an import statement to the main source file:

    #import <CoreData/CoreData.h>

Adopt Garbage Collection

To reduce the amount of code, the tutorial uses garbage collection (see Garbage Collection Programming Guide). Change the project build settings to use garbage collection; then remove the references to autorelease pools, and add a function call to start the garbage collector:

  1. In the project’s Build Settings, change the garbage collection setting (“Objective-C Garbage Collection”) to Required.

  2. At the beginning of the main source file, import the auto header file:

    #include <objc/objc-auto.h>
  3. In the main function, remove the lines that create and drain the autorelease pool, and the log statement:

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSLog(@"Hello, World!");
    [pool drain];
  4. At the beginning of the main function add a function call to start the garbage collector:

    objc_startCollectorThread();

Your main source file should look like this:

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#include <objc/objc-auto.h>
 
int main (int argc, const char * argv[]) {
    objc_startCollectorThread();
 
    return 0;
}

What Happened?

You created a very simple Foundation Tool project and added the Core Data framework. This emphasizes that there’s no need to use a graphical user interface using the Application Kit or UIKit. 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: 2010-05-24

Did this document help you? Yes It's good, but... Not helpful...