Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mac@newlife

macrumors newbie
Original poster
Jul 5, 2005
5
0
Hi Folks, I just followed to the tutorial of Apple, and I got an error that
"/ConverterController.m:12: error: 'converter' undeclared (first use in this function)" Can anyone help me?

Converter.h
--------------------------------
#import <Cocoa/Cocoa.h>

@interface Converter : NSObject
{
}

- (float)convertAmount:(float)amt atRate:(float)rate;
@end

Converter.m
-------------------------------
#import "Converter.h"

@implementation Converter

- (float)convertAmount:(float)amt atRate:(float)rate;
{
return (amt * rate);
}

@end

ConverterController.h
--------------------------------------------------
#import <Cocoa/Cocoa.h>

@interface ConverterController : NSObject
{
IBOutlet NSTextField *dollarField;
IBOutlet NSTextField *rateField;
IBOutlet NSTextField *totalField;
}
- (IBAction)convert:(id)sender;
@end

ConverterController.m
-------------------------------------------------
#import "ConverterController.h"
#import "Converter.h"

@implementation ConverterController

- (IBAction)convert:(id)sender
{
float rate, amt, total;
amt = [dollarField floatValue];
rate = [rateField floatValue];

total = [converter convertAmount:amt atRate:rate];

[totalField setFloatValue:total];
[rateField selectText:self];
}

- (void)awakeFromNib
{
[[rateField window] makeKeyAndOrderFront:self];
[rateField selectText:self];
}

@end
 
Put the [CODE ] and [/CODE ] tags around your code (without the space after each code in my example) and it will not create the smiley expressions and therefore be easier to read.
 
You need to add an outlet called "converter" to the ConverterController class in Interface Builder, and connect it to the Converter object that you instantiated. From the tutorial:

ConverterController needs to access the text fields of the interface, so you’ve just provided outlets for that purpose. But ConverterController must also communicate with the Converter class (yet to be defined). To enable this communication, add an outlet named converter to ConverterController.

While connecting ConverterController’s outlets, you probably noticed that one outlet remains unconnected: converter. This outlet identifies an instance of the Converter class in the Currency Converter application, but this instance doesn’t exist yet.

Define the Converter class. This should be pretty easy because Converter, as you might recall, is a model class within the Model-View-Controller paradigm. Since instances of this type of class don’t communicate directly with the interface, there is no need for outlets or actions. Here are the steps to be completed:

  1. In the Classes display, make Converter a subclass of NSObject.
  2. Instantiate the Converter class.
  3. Make an outlet connection between ConverterController and Converter. Hint: Control-drag from the ConverterController instance to the Converter instance.
  4. Save MainMenu.nib.

You'll also need to add the following code to ConverterController.h under the text field declarations:

Code:
IBOutlet id converter;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.