How to Print Boolean Flag in Nslog

How to print Boolean flag in NSLog?

Here's how I do it:

BOOL flag = YES;
NSLog(flag ? @"Yes" : @"No");

?: is the ternary conditional operator of the form:

condition ? result_if_true : result_if_false

Substitute actual log strings accordingly where appropriate.

how to print out bool in objective c

%@ is for objects. BOOL is not an object. You should use %d.

It will print out 0 for FALSE/NO and 1 for TRUE/YES.

How do I print out Bool values with words?

Try this....

'%d', 0 like false, 1 like true

BOOL b; 
NSLog(@"Bool value: %d",b);

or

NSLog(@"bool %s", b ? "true" : "false");

Hope i helped.

Issue with NSLog when printing BOOL type

%@ 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

NSLog(@"Auto Flag: %@",object.autoFlag? @"True":@"False");

How to print BOOLs

NSLog(parsingResult ? @"YES" : @"NO");

NSLog symbol print on console?

try this

NSLog(@"str : %%");

Thanks

Use NSLog print variable,why add a nil?

The signature of NSLog is void NSLog (NSString *format, ...);.

So the first argument is rather a format instead of a literal string. The second (and all following) arguments are the substitution values for the format string.

You should not replace the format string with the string you want to log. If your string contains format specifiers like %d NSLog will try to replace them but will fail to do so as you have not entered a substitution.

You should always log with NSLog(@"%@", string) when you want to log string.



Related Topics



Leave a reply



Submit