首先看下objc.h里面的定义
1 /// Type to represent a boolean value. 2 #if !defined(OBJC_HIDE_64) && TARGET_OS_IPHONE && __LP64__ 3 typedef bool BOOL; 4 #else 5 typedef signed char BOOL; 6 // BOOL is explicitly signed so @encode(BOOL) == "c" rather than "C" 7 // even if -funsigned-char is used. 8 #endif 9 10 #if __has_feature(objc_bool) 11 #define YES __objc_yes 12 #define NO __objc_no 13 #else 14 #define YES ((BOOL)1) 15 #define NO ((BOOL)0) 16 #endif
从上面的定义我们发现布尔变量的值为 YES/NO,或 1/0 。YES 或 1 代表真,NO 或 0 代表假。比如你定义了一个布尔变量并赋了值
因此我们可以定义 BOOL b1 = YES; BOOL b2 = NO; 或者定义BOOL b3 = 1; BOOL b4 = 0;