简体   繁体   中英

Several errors in Objective-c

I did every thing, at least I tried to do everything JUST like the tutorial, but it gives me now 5 errors and 1 warning...
I am just beginning with Objective-c, so please explain your solutions.

Here's my code: (Errors marked and described in comments)

CalculatorViewController.h:

//
//  CalculatorViewController.h
//  Calculator
//
//  Created by Me on 06-04-12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface CalculatorViewController : UIViewController {
    IBOutlet UILabel *display;
    CalculatorBrain *brain; // error: "Expected specifier-qualifier-list before 'CalculatorBrain':
    NSString *waitingOperation;
}

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

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

@end

CalculatorViewController.m:

//
//  CalculatorViewController.m
//  Calculator
//
//  Created by Me on 06-04-12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "CalculatorViewController.h"

@implementation CalculatorViewController 

- (CalculatorBrain *) brain { // error: "Expected ')' before 'CalculatorBrain'"
    if (!brain) { // error: "'brain' undeclared"
        brain  = [[CalculatorBrain alloc] init]; // error: "'CalculatorBrain' undeclared"
    }
    return brain;
} // warning: Control reaches end of non-void function

-(IBAction)digitPressed:(UIButton *)sender {
    if ([waitingOperation isEqualToString:@""]) {
        NSString *digit = [[sender titleLabel] text];
        [display setText:digit];
    }
    else {
        // Do calculations if everything works, now just log something to check if it works
        NSLog(@"Joepie!");
    }

}

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

}

- (void)dealloc {
    [super dealloc];
}

@end

You are missing

#import "CalculatorBrain.h"

at the top of your.h file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM