-1

I JUST started a new XCode Project. The code I have added in so far is this:

.h

@interface GameScreen : UIViewController {


    IBOutlet UIImageView *pimple;
    IBOutlet UILabel *label;
}
@property (nonatomic, retain) UIImageView *pimple;
-(void)checkcollision;

.m

@synthesize pimple;


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *myTouch = [[event allTouches] anyObject];
    pimple.center = [myTouch locationInView:self.view];

    [self checkcollision];
}

- (void)checkcollision {

    if (label.text = @"0") {
        label.text += 1;
    }
}

My debugging console only sais one line:

Program received signal: “EXC_BAD_ACCESS”. kill

Pls help

3
  • the void should be -(void) i dont know why that happened when i copied the code in
    – user722566
    May 28, 2011 at 8:53
  • In the if statement, you probably mean to use ==, not =
    – oefe
    May 28, 2011 at 8:58
  • 1
    Voted to close. Have we become DebugMyCode.stackexchange?
    – Abizern
    May 28, 2011 at 10:52

3 Answers 3

3

label.text += 1; is wrong. You can't add an integer onto an NSString object.

you will have to do label.text = [NSString stringWithFormat:@"%d", ([label.text intValue] + 1)];

2
  • Of course I assumed you wanted to add, appending it is also possible. May 28, 2011 at 8:56
  • And check string equality like this [label.text isEqualToString:@"0"] May 28, 2011 at 9:00
1

you can use "NSZombieEnabled" to track your problem, how to use it?, and also refer this link Break on EXC_BAD_ACCESS in XCode?

0

The error is because you're assigning an integer to a NSString property.

label.text += 1;

Not the answer you're looking for? Browse other questions tagged or ask your own question.