Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print Boolean flag in NSLog?

Is there a way to print value of Boolean flag in NSLog?

like image 337
Devang Avatar asked Jun 15 '11 13:06

Devang


People also ask

How do I print a Boolean value?

The println(boolean) method of PrintStream Class in Java is used to print the specified boolean value on the stream and then break the line. This boolean value is taken as a parameter. Parameters: This method accepts a mandatory parameter booleanValue which is the boolean value to be written on the stream.


2 Answers

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.

like image 108
BoltClock Avatar answered Oct 12 '22 15:10

BoltClock


%d, 0 is FALSE, 1 is TRUE.

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

or

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

On the bases of data type %@ changes as follows

For Strings you use %@ For int  you use %i For float and double you use %f 
like image 29
SashaQbl Avatar answered Oct 12 '22 15:10

SashaQbl