Reputation: 4658
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?.
Upvotes: 8
Views: 2349
Reputation: 71
EXC_BAD_ACCESS means your code is pointing to inaccessible memory address.
Such as:
Your second line code causes a crash because of "%@". iOS thinks that the pointer you sent to it is an object, it access the property of that object, which doesn't exist, then it throws the EXC_BAD_ACCESS.
reference: Apple's Investigating Memory Access Crashes
Upvotes: 1
Reputation: 90117
%@
only works with objects. And toInterfaceOrientation is not an object.
As you can see in the documentation for UIInterfaceOrientation
it's just an enum.
Upvotes: 13
Reputation: 957
toInterfaceOrientation is a enum variable... so if you want to print log of it you have to use %d ...... . and %@ mostly used for objects ...
Use this Code :
NSLog(@"EXC_BAD_ACCESS :%d",toInterfaceOrientation);
Upvotes: 1
Reputation: 2078
%@ is for objects only.
UIInterfaceOrientation
is an enum:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/doc/c_ref/UIDeviceOrientationPortrait
When you use %@ it is basically calling:
[UIInterfaceOrientation descriptionWithLocale]
Obviously this will cause a EXC_BAD_ACCESS
Upvotes: 2
Reputation: 7136
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.
Upvotes: 6
Reputation: 716
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?
Upvotes: 2