IPhone nslog "EXC_BAD_ACCESS"

I am trying to use NSLog to print console messages. Sometimes the error "EXC_BAD_ACCESS" occurs when calling

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

Here I just want to see what the arguments passed to the function contain. The first NSLog works great. The second calls "EXC_BAD_ACCESS" and I don’t understand why ?.

+7
source share
5 answers

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

As you can see in the documentation for UIInterfaceOrientation this is just enum .

+13
source

The second NSLog crashes because you are trying to print an integer as NSObject (% @ instead of% d). UIInterfaceOrientation is an enumeration that does not work.

+6
source

EXC_BAD_ACCESS usually means that you are trying to call an object that has been released from memory. Try enabling NSZombies in your environment variables to see where this is causing the problem.

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

+2
source

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html

% @ is for objects only.

UIInterfaceOrientation is an enumeration: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDevice_Class/Reference/UIDevice.html#//apple_ref/doc/c_ref/UIDeviceOrientationPortrait

When you use% @, it basically calls:

 [UIInterfaceOrientation descriptionWithLocale] 

Obviously this will call EXC_BAD_ACCESS

+2
source

toInterfaceOrientation is an enum variable ... so if you want to print a log you need to use% d ....... and% @ is mainly used for objects ...

Use this code :

NSLog (@ "EXC_BAD_ACCESS:% d", toInterfaceOrientation);

+1
source

All Articles