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

Cryotech079

macrumors newbie
Original poster
Feb 4, 2011
2
0
Hey Guy's let me introduce myself. I'm Daniel a 27 year old guy from Holland that is busy with learning Cocoa. Now i reading a book from Aaron Hillegass "Cocoa programming for MAC OS X" but i have a problem.

I'm busy with creating a random number app. But i'm getting errors when compiling in Xcode. The debugger is telling me: error: expected ']' before 'setIntValue' and error: array subscript is not an integer on a particular piece of code (marked in red).

But what am i doing wrong? I'm now busy for 4 hours allready without finding the error.

Foo.h code:
#import <Cocoa/Cocoa.h>


@interface Foo : NSObject {
IBOutlet NSTextField *textField;
}
- (IBAction)seed:(id)sender;
- (IBAction)generate:(id)sender;
@end

Foo.m code:
#import "Foo.h"


@implementation Foo

- (IBAction)generate:(id)sender
{
//Generate a number between 1 and 100 inclusive
int generated;
generated = (random() % 100) + 1;

NSLog(@"generated = %d", generated)

// Ask the text field to change what it is displayed
[textField setIntValue:generated];
}

- (IBAction)seed:(id)sender
{
//seed the random number generator with the time
srandom(time(NULL));
[textField setStringValue:mad:"Generator seeded"];
}

@end
 
Last edited:
Missng ; on the previous line, the NSLog. There might be other issues, but fix that first.

-Lee

Edit: Also, welcome. In the future wrap your code in [code][/code] tags. It makes it much easier to read your code and help.
 
Thanks Lee!!!! That was it.... Currently feeling myself a little dumb... reading over it for 4 hours! But many thanks!!!!

Missng ; on the previous line, the NSLog. There might be other issues, but fix that first.

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