Every Cocoa application starts life as a project. A project is a repository for all the elements that go into the application, such as source code files, frameworks, libraries, the application’s user interface, sounds, and images. You use the Xcode application to create and manage your project. In this chapter, you will learn to create a project, and see what all the various parts of a project are for. In the process, you will learn how to navigate the Xcode user interface, and you will learn about all the different folders available for you.
To open Xcode:
In the Finder, go to /Developer/Applications
.
Double-click the icon, shown in Figure 2-1.
The first time you start Xcode, it takes you through a quick setup process. The default settings should work for the majority of users.
This section will guide you through the process of creating a project. Though it is focused on creating a project suitable for Currency Converter, you will learn about other options available to you when creating a new project.
To create a project, choose File > New Project. The New Project Assistant appears.
Xcode can build many different types of applications, including everything from Carbon and Cocoa applications to Mac OS X kernel extensions and Mac OS X frameworks. For this tutorial, use the Cocoa Application template.
Select Cocoa Application and click Choose…, as shown in Figure 2-2
Type the project’s name, Currency Converter, in the save sheet, and choose where you want to save the project. Then click save.
Xcode creates the project’s files and displays the project window, shown in Figure 2-3.
The Groups & Files list allows you to easily navigate through your project’s files and traits. All the source files, images, and other resources that make up a project are grouped in the project group, the first item in the Groups & Files list; this group is named after the project (here, Currency Converter). The project’s files are grouped into subgroups, such as Classes, Other Sources, Resources, and so on, as shown in Figure 2-3. Groups are very flexible because they do not necessarily reflect either the on-disk layout of files in the project or the way the build system handles those files. Groups are purely for organizing your project. The groups created by Xcode should be suitable for most developers, but you can customize them however you like.
These are the groups Xcode sets up for Cocoa applications:
Classes. This group holds all the classes required by your application.
Other Sources. This group contains the main.m
file, which defines the main
function that runs the application. (You shouldn’t have to modify this file.) It also contains Currency Converter_Prefix.pch
. This “prefix header” helps Xcode reduce compilation time. You don’t need to worry about this file.
Resources. This group contains the nib files and other resources that specify the application’s user interface.
Frameworks. This group contains the frameworks (which are similar to libraries) that the application uses.
Products. This group contains the results of project builds and is automatically populated with references to the products created by each target in the project.
Below the project group are other groups, including smart groups. Smart groups—identified by the purple folders on the left side of the list—allow you to access the project’s files using custom rules in a way similar to using smart playlists in iTunes.
These are some of the other groups in the Groups & Files list:
Targets. This group lists the end results of your builds. This group usually contains one target, such as an application or a framework, but it can consist of multiple items.
Executables. This group contains the executable products your project creates.
Errors and Warnings. This group displays the errors and warnings encountered in your project when you perform a build.
Curious folks might want to look in the project directory in Finder to see the files it contains. Among the project files are:
Currency Converter.xcodeproj
This package contains information that defines the project. You should not modify it directly. You can open your project by double-clicking this package.
main.m
An Objective-C file, generated for each project, that contains the main
function of the application.
English.lproj
A directory containing resources localized to the English language. In this directory are nib files automatically created for the project. You may find other localized resource directories, such as Dutch.lproj
.
In this chapter, you made an Xcode project that will contain all the resource files for a Cocoa application. In the next chapter, you will learn how to create the model, the basic functionality behind an application.
Last updated: 2009-08-03