Is there a format specifier that works with Boolean values?

后端 未结 6 1714
悲&欢浪女
悲&欢浪女 2021-02-12 14:17

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:

6条回答
  •  情深已故
    2021-02-12 14:28

    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.

提交回复
热议问题