-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

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
user722566
  • 203
  • 1
  • 5
  • 16

3 Answers3

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)];

Deepak Danduprolu
  • 44,595
  • 12
  • 101
  • 105
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?

Community
  • 1
  • 1
rptwsthi
  • 10,094
  • 10
  • 68
  • 109
0

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

label.text += 1;
Rog
  • 18,602
  • 6
  • 76
  • 97