Error: Syntax Error before '-' token.

Discussion in 'Mac Programming' started by lase, Aug 11, 2009.

  1. lase macrumors newbie

    Joined:
    Dec 24, 2008
    #1
    I'm at wits ends trying to fix this. I've been googling for the last hour about this.

    Any ideas?

    The error is up in the @interface for Car...

    Code:
    #import <Foundation/Foundation.h>
    
    //classes
    
    @interface Car : NSObject
    {
    	-(NSString *) carModel;
    	-(NSString *) ownerName;
    	-int gasAmount;
    }
    
    -(void) setModel: (NSString *) m;
    -(void) setOwner: (NSString *) o;
    -(void) setGas: (int) g;
    
    @end
    
    @implementation Car
    {
    	-(void) setModel: (NSString *) m 
    	{
    		carModel = m;
    	}
    	-(void) setOwner: (NSString *) o
    	{
    		ownerName = o;
    	}
    	-(void) setGas: g
    	{
    		gasAmount = g;
    	}
    @end
    		
    		
    
    
    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    
    	Car *myCar = [[Car alloc] init];
    	
    	[myCar setModel:@"Ford F150"];
    	[myCar setOwner:@"Anthony Crognale"];
    	[myCar setGas: 1];
    	
    	NSLog([myCar carModel]);
    	NSLog([myCar ownerName]);
    	NSLog([myCar gasAmount]);
    	
        // insert code here...
        [pool drain];
        return 0;
    }
    
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    Don't put dashes or paretheses with your variable declarations. It should be like this:

    Code:
    @interface Car : NSObject {
        NSString *carModel;
        NSString *ownerName;
        int gasAmount;
    }
    
    The method declarations are fine.
     
  3. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #3
    Hmm, your method implementations need some work though. You need to write "(int) g" for setGas and in the other two where you are assigning objects you need to do some checks and retain/release if you're not using garbage collection. Also have a lot at the documentation for the @synthesize and @property keywords.
     

Share This Page