I want to do something like this:
NSLog(@\"You got: %x\", booleanValue);
where x is the specifier. But I can\'t find one! I want to avoid:
For os_log
use
os_log("results in true/false: %{bool}d", myBool)
os_log("results in YES/NO: %{BOOL}d", myBool)
If you are on the latest OS, you can also use string interpolation. For more info look at Format Custom Values in Message Strings
Here are two things that work:
NSLog(@"You got: %@",booleanValue ? @"YES" : @"NO");
or you can cast:
NSLog(@"You got: %d", (int)booleanValue);
Which will output 0 or 1
There's no format specifier that I know of. You can do this:
NSLog(@"You got: %@", (booleanValue ? @"YES" : @"NO"));
Alternately, you could write a little function or macro using the logic above that takes a BOOL and returns the appropriate string. You can then use that function in your log statements.
On Swift
, use String(describing: booleanValue)
For example: os_log("You got %@", log: .default, type: .debug, String(describing: booleanValue))
You can cast it to an int and use %d
:
NSLog(@"You got: %d", (int)booleanValue);
Or use something like this:
NSLog(@"You got: %@", booleanValue ? @"YES" : @"NO");
Yes
Here is the code:
NSLog(@"%hhd",BOOLvariable);
Prints 1 for Yes and 0 for No. Worked for me.