Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialnirmalabasdeo
Python Development Techdegree Student 3,787 PointsError message:Unexpected identifier or '('
I am trying to create a calculator class with methods but keeps getting an error. Error message reads" unexpected identifier or '('. Below is the code.
#import <Foundation/Foundation.h>
@interface Calculator ;NSObject
{
@property float numerator;
@property float denominator;
@property float total;
@end
}
-(void) add;
-(void) divide;
Moderator edited: Markdown added to code to make it render properly on the forums. Category switched to iOS as the code given is Objective-C.
nirmalabasdeo
Python Development Techdegree Student 3,787 PointsYes that is Objective C. I am now learning it so just two methods. But I cant seem to get pass that error to do anything else.
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! I've taken a look at your code and there are a few problems. First, on the line with @interface
you have a semicolon instead of a colon. Secondly, remember that methods are just functions defined inside a class. So your function definitions need to be before the @end
. Third, the curly braces are not needed for your particular example. We would use them when defining what happens inside the method. But even when I reworked your code, I still had to rebuild the file to get rid of all the errors. Take a look at my code that was able to build.
#import <Foundation/Foundation.h>
@interface Calculator : NSObject
@property float numerator;
@property float denominator;
@property float total;
-(void) add;
-(void) divide;
@end
Hope this helps!
nirmalabasdeo
Python Development Techdegree Student 3,787 PointsHello Jennifer,
Thank you for your response and it did help big time!
Jon Wood
9,884 PointsJon Wood
9,884 PointsIs that for iOS? It looks like Objective-C :p