读书人

BOOL跟bool

发布时间: 2013-03-26 09:54:34 作者: rapoo

BOOL和bool

BOOL 和 bool 不是同一个对象,不能混为一谈。

上一个例子吧:

bool b1 = true;

BOOL b2 = true;

bool b3 = 11;

BOOL b4 = 11;

if(b1) NSLog(@"b1 is true");

if(b2) NSLog(@"b2 is true");

if(b3) NSLog(@"b3 is true");

if(b4) NSLog(@"b4 is true");

输出结果:

b1 is true;

b2 is true;

b3 is true;

b4没有输出。

  1. BOOL a = YES;
  2. BOOL b = NO;
  3. if(a == YES){
  4. NSLog(@"a==YES");
  5. }
  6. if(b == NO){
  7. NSLog(@"b==NO");
  8. }
  9. if(a){
  10. NSLog(@"a is true");
  11. }
  12. if(b){
  13. NSLog(@"b");
  14. }

输出结果:

  1. a==YES
  2. b==NO
  3. a is true














读书人网 >移动开发

热点推荐