Online Book Reader

Home Category

Learn Objective-C on the Mac - Mark Dalrymple [6]

By Root 883 0

Also, remember that we’ve set up a message forum for readers to discuss the exercises and content of this book. So if you get stuck, or want to chat with us and other Cocoa developers about any Cocoa programming topics, head over to http://learncocoa.org and register for the discussion forum.

That said, if you’ve got your developer tools installed, turn the page. If not, get to it! Then let’s go!

Chapter 2

Hello, World

As you’re probably well aware, it has become something of a tradition to call the first project in any book on programming “Hello, World.” Following the “if it ain’t broke, don’t fix it” guideline, we’ll stick with tradition.

Building “Hello, World”


By now, you should have Xcode installed on your machine. You should also have the Learn Cocoa Projects folder ensconced, safely, somewhere on your hard drive. If by some set of circumstances you don’t, go directly to Chapter 1 (do not pass Go, do not collect $200) and reread the appropriate sections.

The first project we’ll be working with is located in the 02.01 - Hello, World folder.

Launch Xcode, which is located in the folder /Developer/Applications. Just in case you’ve never used Xcode before, we’re going to walk you through the process of creating a new project.

Start by selecting New Project… from the File menu, or by typing ⌘N. When the New Project Assistant comes up (see Figure 2-1), select Application from under the Mac OS X heading in the left column, then select the Cocoa Application icon from the upper-right pane and press the Choose… button.

Figure 2-1. Selecting the Cocoa Application project template from Xcode’s New Project Assistant

You’ll be prompted for a project name and save location using the standard save sheet (see Figure 2-2). Type in the project name of Hello World. You can choose to save the project in your Documents folder, or you can create a separate folder to hold the Xcode projects that you build yourself. It really doesn’t matter where you save an Xcode project, but you may find it easier to find them later if you pick one place and always save your projects there.

Figure 2-2. Naming your project and selecting the save location

Once you select a filename and location, a new project window will appear (as shown in Figure 2-3). Although you might already be familiar with Xcode, let’s take a second to look at the project window. This is where we will be spending an awful lot of our time, so we want to make sure we’re all on the same page.

Figure 2-3. Your project’s main window in Xcode

Your project window features a toolbar across the top, which gives you ready access to a bunch of commonly used commands. Below the toolbar, the window is divided into three main sections, or panes.

The pane that runs down the left side of the window is called the Groups & Files pane. All of the resources that make up your project are grouped here, as are a number of relevant project settings. Clicking on the little triangle to the left of an item expands that item to show any available sub-items. If you click on the triangle to the left of an expanded item, you will hide its sub-items.

The top right pane is called the Detail View and shows you detailed information about items selected in the Groups & Files pane. If nothing is selected in the Groups & Files pane, the Detail View shows all the files that make up your project. The lower right pane is called the Editor pane. If you select a single file in either the Groups & Files pane or the Detail pane, and Xcode knows how to display or edit that kind of file, the contents of the file will be displayed in the Editor pane. This is where you will be writing and editing all of your application’s source code.

NOTE: Many developers like to get rid of the Detail View when they are working in the editor, so they have more screen space devoted to editing code; you can toggle the Detail View by pressing ⌘E.

Turn your attention to the Resources folder in the Groups & Files pane. Double-click the Resources folder or single-click the disclosure triangle

Return Main Page Previous Page Next Page

®Online Book Reader