Is there a way to print value of Boolean flag in NSLog?
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.
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.
%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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With