O'Reilly logo

Learning Cocoa by Apple Computer Inc

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Define the Classes of Currency Converter

In this section you’ll define controller and model classes for Currency Converter.

Create the ConverterController Subclass

You’ll recall from Chapter 6 that you must go to the Classes display of the nib file window to define a class. Let’s start with the ConverterController class:

  1. In Interface Builder, select the Classes display of the MainMenu.nib window.

  2. Create an NSObject subclass called ConverterController.

Define Outlets for ConverterController

ConvertorController needs access to the text fields of the interface, so you must create outlets for them. ConverterController must also communicate with the Converter class (yet to be defined) and thus requires a fourth outlet for that purpose.

  1. Select ConverterController in the Classes window.

  2. Click the electrical outlet icon to the right of the class.

  3. Choose Add Outlet from the Classes menu.

  4. Name this outlet rateField and press Return.

  5. Since the rateField outlet is still selected, all you have to do to create more outlets is press Return. Do this once to create the dollarField outlet, and again for the totalField outlet.

  6. Add an outlet named converter to ConverterController.

Define Actions for ConverterController

ConverterController has one action method, convert:. When the user clicks the Convert button, a convert: message is sent to the target object, an instance of ConverterController. Action refers both to a message sent to an object when the user clicks a button or manipulates some other ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required