Parse error in Apple XCode Tutorial

Discussion in 'Mac Programming' started by vtecinc, Dec 31, 2005.

  1. macrumors newbie

    Joined:
    Dec 31, 2005
    #1
    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
     
  2. macrumors member

    Joined:
    Nov 23, 2005
    #2
    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.
     
  3. thread starter macrumors newbie

    Joined:
    Dec 31, 2005
    #3
    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
     

Share This Page