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

    Joined:
    Feb 4, 2011
    #1
    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
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    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.
     
  3. Cryotech079 thread starter macrumors newbie

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

     
  4. balamw Moderator

    balamw

    Staff Member

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

    B
     

Share This Page