Problems with code

Discussion in 'Mac Programming' started by Cryotech079, Feb 4, 2011.

  1. Cryotech079, Feb 4, 2011
    Last edited: Feb 4, 2011

    Cryotech079 macrumors newbie

    Feb 4, 2011
    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;

    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
    [textField setStringValue:mad:"Generator seeded"];

  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    Missng ; on the previous line, the NSLog. There might be other issues, but fix that first.


    Edit: Also, welcome. In the future wrap your code in [code][/code] tags. It makes it much easier to read your code and help.
  3. Cryotech079 thread starter macrumors newbie

    Feb 4, 2011
    Thanks Lee!!!! That was it.... Currently feeling myself a little dumb... reading over it for 4 hours! But many thanks!!!!

  4. balamw Moderator


    Staff Member

    Aug 16, 2005
    New England
    If nothing else it avoids having Objective-C code frown on you so much. :p


Share This Page