Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What format specifier should be used for BOOL? [duplicate]

Possible Duplicate:
Objective c formatting string for boolean?

What NSLog %-specifier should be used to literally see YES or NO when printing a BOOL?

like image 634
James Raitsev Avatar asked Feb 27 '12 02:02

James Raitsev


2 Answers

BOOL var = YES;
NSLog(@"var = %@", (var ? @"YES" : @"NO"));

BOOL is merely an alias (typedef) for signed char.

The specifiers supported by NSLog are documented here.

like image 53
Emile Cormier Avatar answered Sep 20 '22 14:09

Emile Cormier


Objective-C booleans (BOOL) are simply typedefs to signed char. Therefore, they are not objects, and aren't handled any differently from other primitive numbers. If you don't care about seeing YES and NO, you can simply print them out as you would any other number (with %d, for instance). If you would like to see YES and NO, you can follow Emile's suggestion.

like image 24
Itai Ferber Avatar answered Sep 19 '22 14:09

Itai Ferber