chinabenjamin66
chinabenjamin66

Reputation: 177

Is there a method can convert a BOOL into NSString in 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.

Upvotes: 4

Views: 7138

Answers (1)

Jeow Li Huan
Jeow Li Huan

Reputation: 3796

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

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

Upvotes: 12

Related Questions