(XCode 4.3)
Why does the following crash at the NSLog statement with EXC_BAD_ACCESS?
BOOL autoFlag
@property BOOL autoFlag
@synthesize autoFlag
[object setAutoFlag:YES]
NSLog(@"%@", [object autoFlag]); //crashes here in debugger with EXC_BAD_ACCESS
I managed to get around it with NSLog(@"%d"..., which prints 1, but why doesn’t @"%@" work? I thought it just converts the value to a string?
%@ is used to print the description of objects that are descendants of the NSObject class, this however can be overwritten to make your objects print whatever you want.
Unless autoFlag is an object it will crash your program. It is very common to get these type of errors in NSLog Statements since the compiler cant tell what kind of “thing” you want to print and most of the time it wont be able to know before hand (there are some exceptions in where it will tell you that you are using the wrong identifier).
If what you want to see is something like “True” or “YES” then you need something like