Is there a way to print value of Boolean flag in NSLog?
Apple's FixIt supplied %hhd, which correctly gave me the value of my BOOL.
Note that in Swift, you can just do
let testBool: Bool = true
NSLog("testBool = %@", testBool.description)
This will log testBool = true
We can check by Four ways
The first way is
BOOL flagWayOne = TRUE;
NSLog(@"The flagWayOne result is - %@",flagWayOne ? @"TRUE":@"FALSE");
The second way is
BOOL flagWayTwo = YES;
NSLog(@"The flagWayTwo result is - %@",flagWayTwo ? @"YES":@"NO");
The third way is
BOOL flagWayThree = 1;
NSLog(@"The flagWayThree result is - %d",flagWayThree ? 1:0);
The fourth way is
BOOL flagWayFour = FALSE; // You can set YES or NO here.Because TRUE = YES,FALSE = NO and also 1 is equal to YES,TRUE and 0 is equal to FALSE,NO whatever you want set here.
NSLog(@"The flagWayFour result is - %s",flagWayFour ? YES:NO);
Here is how you can do it:
BOOL flag = NO;
NSLog(flag ? @"YES" : @"NO");
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.
//assuming b is BOOL. ternary operator helps us in any language.
NSLog(@"result is :%@",((b==YES)?@"YES":@"NO"));