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

br-

macrumors member
Original poster
Aug 7, 2006
32
0
Hey guys, I'm just starting out with Cocoa and I'm trying to make a basic GUI calculator app. My problem is that whenever I compile, I get an error saying:

error: parse error before '=' token

It's referring to line 5 of the CSController.h file. Here's all the code:

CSController.h:
Code:
#import <Cocoa/Cocoa.h>

@interface CSController : NSObject
{
    NSMutableString *contents = [NSMutableString stringWithCapacity:10];
    IBOutlet NSTextField *textField;
    IBOutlet NSTextView *textView;
}
- (IBAction)clear:(id)sender;
- (IBAction)divide:(id)sender;
- (IBAction)dot:(id)sender;
- (IBAction)eight:(id)sender;
- (IBAction)enter:(id)sender;
- (IBAction)equals:(id)sender;
- (IBAction)five:(id)sender;
- (IBAction)four:(id)sender;
- (IBAction)minus:(id)sender;
- (IBAction)multiply:(id)sender;
- (IBAction)nine:(id)sender;
- (IBAction)one:(id)sender;
- (IBAction)plus:(id)sender;
- (IBAction)seven:(id)sender;
- (IBAction)six:(id)sender;
- (IBAction)three:(id)sender;
- (IBAction)two:(id)sender;
- (IBAction)zero:(id)sender;

@end

CSController.m
Code:
#import "CSController.h"

@implementation CSController

- (IBAction)clear:(id)sender
{
}

- (IBAction)divide:(id)sender
{
}

- (IBAction)dot:(id)sender
{
}

- (IBAction)eight:(id)sender
{
	[contents appendString:@"8"]
	[textField setStringValue:contents]
}

- (IBAction)enter:(id)sender
{
}

- (IBAction)equals:(id)sender
{
}

- (IBAction)five:(id)sender
{
}

- (IBAction)four:(id)sender
{
}

- (IBAction)minus:(id)sender
{
}

- (IBAction)multiply:(id)sender
{
}

- (IBAction)nine:(id)sender
{
}

- (IBAction)one:(id)sender
{
}

- (IBAction)plus:(id)sender
{
}

- (IBAction)seven:(id)sender
{
}

- (IBAction)six:(id)sender
{
}

- (IBAction)three:(id)sender
{
}

- (IBAction)two:(id)sender
{
}

- (IBAction)zero:(id)sender
{
}

@end

And my main.m which I haven't modified:
Code:
#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[])
{
    return NSApplicationMain(argc,  (const char **) argv);
}

Thanks.
 

mduser63

macrumors 68040
Nov 9, 2004
3,042
31
Salt Lake City, UT
You can't initialize a variable/object (in this case 'contents') in the interface section. You only declare stuff in the interface. You can initialize things in the implementation section.
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
To expand on what mduser63 is saying you would normally do your instance level initialisation in the init method (unless you are going to be woken from a nib file then you might want to do it in awakeFromNib).

So for example:

Code:
- (id) init
{
if ([super init])
{
contents = [[NSMutableString stringWithCapacity:10] retain];
return self;
}
return nil;
}

As we have retained the contents (no GC till Leopard!) we need to release it when the object dies:

Code:
-(void) dealloc
{
[contents release];
[super dealloc];
}

I would recommend getting a book and reading it!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.