I am setting the value of a key in an NSDisctionary using this:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesEnded currentcolor: %@", currentColor);
if (currentTool == @"paint") {
NSLog(@"End Paint");
CGPoint point = [[touches anyObject] locationInView:self.view];
MaskPath * myNewPath = [mapView.drawthis containsPoint:point];
[myNewPath.attributes setValue:currentColor forKey:@"fill"];
[mapView setNeedsDisplay];
} else {
NSLog(@"End Pattern");
currentColor = @"1.png";
CGPoint point = [[touches anyObject] locationInView:self.view];
MaskPath * myNewPath = [mapView.drawthis containsPoint:point];
[myNewPath.attributes setValue:currentColor forKey:@"fill"];
[mapView setNeedsDisplay];
}
}
If I try to log the value of currentColor the app crashes with exc bad access (line 3)
If I take the Log out and go with the hardcoded value everything works fine. It also works fine with the first part of the if statement. I’ve checked the function that assigns currentColor and it is delivering the correct values. If I hard code the value of currentColor at that point it works fine. I’ve run the analyzer and I’ve got no memory leaks or issues. How else can I track this issue down?
One glaring issue is that you are working with an autorelease variable as evidenced by your example. Most likely you are doing the same thing outside of that method.
I recommend you make currentColor a property:
Then, to set it, you would do something like this:
Since you declared the currentColor property with a retain, you will not get a bad access when you pass it to your NSLog:
If you already DO have a currentColor property and you are simply assigning the ivar, then you should be doing:
To sum it up: