Apples Currency Converter Tutorial / Objective-C NOOB Question

ngcomputing

Registered
Hi, just going through Apples tutorial to build the Currency converter. I have a question about the code in the tutorial. When adding the code to the implementation of the convert: method the sample is as follows :

here is the link : http://developer.apple.com/document...jCTutorial/chapter04/chapter_4_section_6.html

- (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];
}

However, I always get a warning that Converter may not respond to convertAmount:amt. And, of course the app doesn't run properly.

I changed the code, and it works, to :

...
Converter *cvt = [[Converter alloc] init];
total = [cvt convertAmount:amt atRate:rate];
[totalField setFloatValue:total];
[rateField selectText:self];
[cvt release];
}


Coming from other OOP languages, it is customary to declare an instance of an object before you implement it's methods. for example in PHP I would do something like :

$myobj = new Converter();
$myobj->convertAmount(amt,rate);


I'm just curious if this is just a mistake on behalf of the tutorials author and if the changes I made is the "proper" way to declare and implement objects, something I'm missing -- any suggestions?


Thanks -
 
The reason your code didn't work initially is because "converter" in the tutorial is actually an instance of the object Converter. Note the smaller case. You were meant to create an outlet called "converter" in the class ConverterController.
 
Back
Top