Is there a format specifier that works with Boolean values?
问题 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: if (booleanValue) { NSLog(@"You got: YES"); } else { NSLog(@"You got: NO"); } Any ideas? The docs didn't have a Boolean specifier. %@ didn't work either. 回答1: Here are two things that work: NSLog(@"You got: %@",booleanValue ? @"YES" : @"NO"); or you can cast: NSLog(@"You got: %d", (int)booleanValue); Which will output 0 or 1 回答2: You can cast it to an int and