Mac OS X Reference Library Apple Developer
Search

Creating the Project and Interface

This part of the tutorial guides you through building the Currency Converter application and in the process teaches you the steps essential to building a Cocoa application using Cocoa bindings.

Create a New Project

Although the application you’ll build in this tutorial is too simple to demonstrate the full power of Cocoa bindings, its simplicity will help you immediately grasp the potential of Cocoa bindings.

Cocoa bindings is integrated into the Cocoa framework, so any Cocoa application can use it. The Currency Converter application you’ll build is a Cocoa document-based application. Follow these steps to create the initial project:

  1. Launch the Xcode application, located in /Developer/Applications.

  2. Choose New Project from the File menu.

  3. Select Cocoa Application in the Xcode Project Assistant, and click Next (as shown in Figure 1-1).

  4. Enter the project name (for example, enter “CurrencyConverter”) and a destination folder for the project.

  5. After creating the project, open MainMenu.nib in Interface Builder by double-clicking its icon in the project Resources folder.

Figure 1-1  Select the Cocoa Application project type

Select the Cocoa Document-based Application project type

Interface Builder contains a palette—called Controllers, shown in Figure 1-2 —that contains the bindings controllers you can drag to your nibs.

Figure 1-2  Controllers palette

Controllers palette

The Bindings pane in the inspector allows you to view the bindings for a selected object. The contents of the Bindings pane changes depending on the object selected in Interface Builder. Figure 1-3 shows the pane when the nib file’s main window is selected.

Figure 1-3  Bindings pane

Bindings pane

Build the User Interface

It’s common to begin developing a Cocoa application by prototyping the application’s user interface. Cocoa bindings complements this development approach by helping you build more full-featured prototypes than ever before.

The final Currency Converter user interface for this tutorial is shown in Figure 1-4. Based on the value of the Exchange Rate and Dollars to Convert fields, the application computes and updates the value displayed in the Amount in Other Currency field.

Notice that unlike the traditional Currency Converter, the application doesn’t include a Convert button. Rather, it uses the infrastructure of Cocoa bindings to automatically perform the conversion without requiring the user to click a button.

Figure 1-4  Final Currency Converter application

Final Currency Converter application

Follow these steps to build this user interface:

  1. Set the title of the application window to Currency Converter.

  2. Drag three text fields and three labels from the Text palette.

  3. Change the three labels to “Exchange Rate”, “Dollars to Convert”, and “Amount in Other Currency”.

  4. Arrange the objects and change their labels to match Figure 1-4.

  5. Add a numeric formatter to each of the text fields, as shown in Figure 1-5.

    Figure 1-5  Adding numeric formatters to the text fields




Last updated: 2007-07-10

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