Objective-C Language Logging NSLog and BOOL type

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

There is no format specifier to print boolean type using NSLog. One way to print boolean value is to convert it to a string.

BOOL boolValue = YES;
NSLog(@"Bool value %@", boolValue ? @"YES" : @"NO");

Output:

2016-07-30 22:53:18.269 Test[4445:64129] Bool value YES

Another way to print boolean value is to cast it to integer, achieving a binary output (1=yes, 0=no).

BOOL boolValue = YES;
NSLog(@"Bool value %i", boolValue);

Output:

2016-07-30 22:53:18.269 Test[4445:64129] Bool value 1


Got any Objective-C Language Question?