Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone nslog "EXC_BAD_ACCESS"

Tags:

iphone

Im trying to use the NSLog, to print console messages. The problem is sometimes i receive a "EXC_BAD_ACCESS" error when calling it

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
NSLog(@"Working test %d", toInterfaceOrientation);
NSLog(@"EXC_BAD_ACCESS %@", toInterfaceOrientation);
}

Here i simply want to see what the arguments passed into the function contain. The first NSLog works fine. The second causes an "EXC_BAD_ACCESS" and i dont understand why?.

like image 428
Mads Lee Jensen Avatar asked Feb 27 '11 10:02

Mads Lee Jensen


3 Answers

%@ only works with objects. And toInterfaceOrientation is not an object.

As you can see in the documentation for UIInterfaceOrientation it's just an enum.

like image 76
Matthias Bauch Avatar answered Oct 23 '22 17:10

Matthias Bauch


The second NSLog crash because you try to print an integer as a NSObject (%@ instead of %d). UIInterfaceOrientation is a enum it doesn't work.

like image 41
Yannick Loriot Avatar answered Oct 23 '22 18:10

Yannick Loriot


EXC_BAD_ACCESS usually means you're trying to call an object that's been released from memory. Try turning on NSZombies in your environment variables to see where it's causing the problem

Answer in a similar question here: How to use NSzombie in xcode?

like image 2
Hector204 Avatar answered Oct 23 '22 16:10

Hector204