Reputation: 3917
I have been working on this tutorial at Apple's documentation at http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCTutorial/06Controller/06Controller.html
However, when I try to run and build the code, I get an incompatible types in assignment error.
#import "ConverterController.h"
@implementation ConverterController
- (IBAction)convert:(id)sender {
float amount;
converter = [[Converter alloc]init];
[converter setSourceCurrencyAmount:[dollarField floatValue]];
[converter setRate:[rateField floatValue]];
amount = [converter convertCurrency];
[amountField setFloatValue:amount];
[rateField selectText:self];
}
@end
The error is on the line of code which reads: amount = [converter convertCurrency];
I can't figure out what is wrong with the code.
Can you help? Thank you.
Upvotes: 0
Views: 1209
Reputation: 486
Did you complete the previous parts of this tutorial? In part 4, Defining the Model, you are asked to create a separate file for Converter objects:
#import "Converter.h"
@implementation Converter
@synthesize sourceCurrencyAmount, rate;
- (float)convertCurrency {
return self.sourceCurrencyAmount * self.rate;
}
@end
This ought to allow Converter objects to recognize that they have a function called convertCurrency that returns a float.
Upvotes: 1
Reputation: 150565
It sounds like convertCurrency
doesn't return a float, which is the type for amount
Upvotes: 1