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 ...

Get Learning Cocoa now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.