PDA

View Full Version : Parse error in Apple XCode Tutorial




vtecinc
Dec 31, 2005, 04:34 PM
I've worked through the Apple XCode Objective-C tutorial that builds a Currency Converter and I'm seeing a parse error on the Converter.m file. I'm using XCode 2.1 on an IBook. The error is "parse error before '-' token "
I'm stumped as to what the issue is. I'm not seeing any difference between what I've typed and the verbiage in the tutorial. I'm really impressed by the XCode tooling so this is doubly frustrating because it all seems like it should be working smoothly. Any help most appreciated.

#import "Converter.h"
@implementation Converter
-(float)convertCurrency:(float)currency atRate:(float)rate {
return currency * rate;
}
@end

Regards,

Doug



Jordan72
Dec 31, 2005, 05:46 PM
If this is how the implementation looks, then it's correct.

#import "Converter.h"
@implementation Converter
- (float)convertCurrency:(float)currency atRate:(float)rate
{
return currency * rate;
}
@end


I looked at the tutorial and there was something strange about the interface. It says to type this:

#import <Cocoa/Cocoa.h>
@interface Converter : NSObject
{
- (float)convertCurrency:(float)currency atRate:(float)rate;
}
@end

That is the error. Try this:

#import <Cocoa/Cocoa.h>
@interface Converter : NSObject
{

}
- (float)convertCurrency:(float)currency atRate:(float)rate;
@end


If that correction doesn't help, try to the tutorial from the beginning and be sure to follow every step exactly. If that doesn't work, it might be the tutorial. Just try other tutorials in books and online. If you are successfull at one, do it two more times just so the process sinks in. You will be less likely to be the one making the error rather wondering if the tutorial is the problem.

vtecinc
Jan 1, 2006, 10:48 AM
You nailed the problem exactly. Moved the method declaration as you suggested and the example builds and runs as expected. Many thanks for spending the time to help me out.

Regards,

Doug