[Objective-C] BOOL类型

来源:互联网 发布:华中地区数据科学会议 编辑:程序博客网 时间:2024/04/27 22:14

参考:http://code.tutsplus.com/tutorials/objective-c-succinctly-data-types--mobile-21986


Object C自己定义了布尔类型:BOOL。它可以取两个值:YES 和 NO

在 /usr/include/objc/objc.h 中可以看到,它们的值分别为 1 和 0,然而,任何大于0值都可以看做YES

#import <objc/objc-api.h>typedef struct objc_class *Class;typedef struct objc_object {  Class isa;} *id;typedef struct objc_selector  *SEL;typedef id      (*IMP)(id, SEL, ...);typedef signed char   BOOL;#define YES             (BOOL)1#define NO              (BOOL)0#ifndef Nil#define Nil 0   /* id of Nil class */#endif#ifndef nil#define nil 0   /* id of Nil instance */#endif
NSLog()函数中BOOL类型的占位符是"%i",如:
BOOL isHuman = 127;if (isHuman) {    // This will execute.    NSLog(@"isHuman is TRUE");}if (isHuman == YES) {    // But this *won't* execute.    NSLog(@"isHuman is YES");}
其中的isHuman的条件满足,而isHuman == YES的条件不满足。


0 0