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

vtecinc

macrumors newbie
Original poster
Dec 31, 2005
2
0
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

macrumors member
Nov 23, 2005
88
0
If this is how the implementation looks, then it's correct.
Code:
#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:

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

That is the error. Try this:
Code:
#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

macrumors newbie
Original poster
Dec 31, 2005
2
0
Resolved

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.