Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method can convert a BOOL into NSString in objective-C?

Tags:

objective-c

Is there a method can convert a BOOL into NSString in objective-C?

for example:

BOOL a = YES;
NSLog(@"a is %i",a);

but the output is "a is 1", I want it to print YES.

like image 462
chinabenjamin66 Avatar asked Dec 20 '22 07:12

chinabenjamin66


1 Answers

You can use the conditional operator to return string from the boolean.

BOOL a = YES;
NSLog(@"a is %@", a ? @"YES" : @"NO");
like image 120
Jeow Li Huan Avatar answered May 10 '23 22:05

Jeow Li Huan