• No results found

Creating a New OS X Project

To create an application, double-click Xcode.app. Click the large Create a New Xcode Project button, shown in Figure 4.8.

C A U T I O N

This book was prepared with Xcode 3.2.3. A preview version of Xcode 4 was released just before the book went to press. Xcode 4 offers a faster compiler and also integrates Interface Builder, which no longer works as a separate stand-alone application. Otherwise the editing and building process for applications remains recognizably similar. For more information about Interface Builder, see Chapter 7.

Figure 4.8

The Xcode start-up screen displays a list of recent projects, if there are any. It’s a good idea to review the Getting Started with Xcode tutorial for a quick overview of some of Xcode’s features.

Xcode displays a template window, shown in Figure 4.9. The window shows a list of file and application templates supported by Xcode. Click Application in the template pane at the left of the window. Then click Cocoa Application in the template pane at the top of the window. Click the Choose button at the bottom right.

N O T E

If you’re using the iPhone version of Xcode, you’ll see an extra division at the top left for iPhone templates. Make sure you select the Application option under Mac OS X and not under iPhone OS — unless you want to create an iPhone app. iPhone and OS X templates have a different structure.

A File Selector sheet drops down from the top of the window. Type in a name such as First in the Save As: field at the top of the sheet, as shown in Figure 4.10. Keep the name short and avoid spaces: the name is used as a prefix for some of the files in the project. Using a long name here creates unwieldy filenames in the project. The name you enter also sets the application name.

Figure 4.9

iPhone OS offers a selection of project templates, described in Chapter 19. Cocoa applications start with a single common Cocoa Application template. The other templates are more specialized and used infrequently.

C A U T I O N

You can change the application name later if you choose to, but it’s extremely difficult to rename project files. Xcode treats the build target, the application, the project name, and the project files as separate entities, with independent names.

Figure 4.10

You can save a new project anywhere on disk, but by default this dialog selects the Developer folder. It’s efficient to create one or more project folders here rather than elsewhere on disk.

Xcode creates a new template with the name you specify and opens a new project window, shown in Figure 4.11.

N O T E

The project window isn’t maximized when it appears. You can either resize it manually or click the green button at the top left of the window to maximize it. For monitors smaller than 26", it’s easier to work with a maximized project. For larger projects, you may find it more productive to have more than one project or file window open at the same time.

Figure 4.11

When you create a new Xcode project, it appears in a single window that is a combined editor and file selector. You can have more than one project window open at a time, either switching between them manually or tiling them on a larger monitor for fast access.

Building a project is a single-click process. There’s no need to define compiler options or to change any of the default settings. Click the Build and Run button at the top of the window. Xcode compiles and runs the application, creating a floating window and a new menu bar, as shown in Figure 4.12.

T I P

As the application compiles, it posts status information at the bottom left of the main Xcode window. Xcode is an incremental compiler — it only compiles files that have been added to the project or have changed. Depending on the speed of your Mac, it takes 15 to 30 seconds to build and run the template application for the first time. Subsequent edits build more quickly.

Although the application seems to be independent, it’s running as a subprocess within Xcode. If you quit Xcode, the application is terminated. You can run an application independently by opening the Build ➪ Debug folder within its project folder and double-clicking the .app file.

This isn’t usually helpful while coding and debugging. Xcode includes separate console and debugging windows, and they can only be accessed when the application is running within Xcode.

The application isn’t complex. It displays an empty window that supports a basic feature set. You can resize the window by dragging the resize box at the bottom right. The red, orange, and green window buttons at the top left respectively close, hide, and restore the window in the usual way. The application adds itself automatically to the Dock when it runs, displaying a default application icon. To quit, choose First ➪ Quit First from the menu.

N O T E

The application isn’t set up to quit automatically when you close the window, so closing the window leaves the menu in place and the application running. You can only quit from the menu.

Figure 4.12

The size and position of the default template’s window are set within the application. By default, it appears on top of Xcode. Although the window is empty, it’s fully functional. It can be dragged, resized, hidden, and so on.

Related documents