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

logicalpath

macrumors newbie
Original poster
Jun 1, 2010
5
0
I have run the console/debug several times now and have tried to modify this file, however it continues to find these 2 errors. Does anyone have any idea where I went wrong with this one?

Code:
#import <UIKit/UIKit.h>
#import "CalculatorBrain.h"

@interface CalculatorStanfordViewController : UIViewController 
{
	IBOutlet UILabel *display;
	CalculatorBrain *brain;
	BOOL userIsInTheMiddleOfTypingANumber;
}

-(IBAction)digitPressed:(UIButton *)sender

{
I get this error code twice right after this curly.

/Users/Paul/Documents/LPD/Stanford Iphone Courses/CalculatorStanford/Classes/CalculatorStanfordViewController.h:21:0 /Users/Paul/Documents/LPD/Stanford Iphone Courses/CalculatorStanford/Classes/CalculatorStanfordViewController.h:21: error: expected ';' before '{' token

Code:
	NSString *digit = [[sender titleLabel] text];

	if (userIsInTheMiddleOfTypingANumber)
	{
		[display setText:[[display text] stringByAppendingString:digit]];
	}
	else 
	{
		[display setText:digit];
		userIsInTheMiddleOfTypingANumber = YES;
	}


-(IBAction)operationPressed:(UIButton *)sender
{

	if(userIsInTheMiddleOfTypingANumber)  {
		[[self brain] setOperand: [[display text] doubleValue]];
		userIsInTheMiddleOfTypingANumber = NO;
	}
	
	NSString *operation = [[[sender titleLabel]text];
	double result= [[self brain] performOperation:operation];
	[display setText:[NSString stringWithFormat:@"%g", result]];
	
	


@end

Below is the m. file.

Code:
#import "CalculatorStanfordViewController.h"

@implementation CalculatorStanfordViewController

-(CalculatorBrain *) brain
{
	if (!brain) brain = [[CalculatorBrain alloc] init];
	return brain;
}

-(IBAction)digitPressed:(UIButton *)sender
{
}

-(IBAction)operationPressed:(UIButton *)sender
{
	NSString *operation = [[sender titleLabel]text];
	double result = [[self brain] performOperation:operation];
	[display setText:[NSString stringWithFormat:@"%g", result]];
}

@end
 
What i found...

NSString *operation = [[[sender titleLabel]text];
in the line above u have 3 square brackets on the left and 2 square brackets on the right.

the methods digitPressed and operationPressed has an opening brackets but not an ending brackets.
 
NSString *operation = [[[sender titleLabel]text];
in the line above u have 3 square brackets on the left and 2 square brackets on the right.

the methods digitPressed and operationPressed has an opening brackets but not an ending brackets.

I just tried that and I'm still getting the same two errors. I just updated the original post with the error code and put it right after the curly that is giving me the error.
 
problems...

post the h file and the m file and then perhaps we'll understand..
if i'm not mistaken, u declared in the h file an interface an u'r trying to implement methods in the h file (should be in the m file), plus u should write @implementation before...
this will help
http://www.otierney.net/objective-c.html
 
It seems that what we see is a header file.

It explains why compiler want to have a semicolon. while you started the implementation.

As robbiduncan says you can not put implementation in the header file.

GL
/petron
 
I updated the original post again, now it has the m. file as well.

I see that some are saying I included an implementation in the h. file, could you tell me what I would need to remove and replace into the m. file? This is my first real program I've ever done so I'm not sure what to do.
 
I updated the original post again, now it has the m. file as well.

I see that some are saying I included an implementation in the h. file, could you tell me what I would need to remove and replace into the m. file? This is my first real program I've ever done so I'm not sure what to do.

Where you have

Code:
-(IBAction)digitPressed:(UIButton *)sender

you need
Code:
-(IBAction)digitPressed:(UIButton *)sender;

in the .h file (in the @interface section). No {. No code. All of that goes in the .m file (in the @implementation section). As you are making such basic, fundamental errors I suggest you stop writing code for a few minutes and read all of Apple's excellent intro to Objective-C. Note that on the iPhone/iPad you are not in a garbage collected environment. If you don't understand something in the document don't skip over it. It is critical to understand what you are doing.
 
Where you have

Code:
-(IBAction)digitPressed:(UIButton *)sender

you need
Code:
-(IBAction)digitPressed:(UIButton *)sender;

in the .h file (in the @interface section). No {. No code. All of that goes in the .m file (in the @implementation section). As you are making such basic, fundamental errors I suggest you stop writing code for a few minutes and read all of Apple's excellent intro to Objective-C. Note that on the iPhone/iPad you are not in a garbage collected environment. If you don't understand something in the document don't skip over it. It is critical to understand what you are doing.

Should -(IBAction) not be in the interface area(h. file)? Would I have to move all of that into the implementation area(m. file)?
 
Should -(IBAction) not be in the interface area(h. file)? Would I have to move all of that into the implementation area(m. file)?

Go and read the document I linked to. Seriously. In short that line appears in both the interface and the implementation. In the interface you are declaring the external interface signature that other objects can see. So you use the ; to terminate the definition there. In the implementation you are implementing the interface you declared so you use the {} pair to enclose the method code.

But as I said: it's time to read rather than type.
 
Go and read the document I linked to. Seriously. In short that line appears in both the interface and the implementation. In the interface you are declaring the external interface signature that other objects can see. So you use the ; to terminate the definition there. In the implementation you are implementing the interface you declared so you use the {} pair to enclose the method code.

But as I said: it's time to read rather than type.

Sorry I was at work so I am just now reading this response.

I'll go ahead and read the link you provided, thank you for your help. I hope you don't mind if I have further questions once I complete that.

Thx
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.