Possible Duplicate:
What values should I use for iOS boolean states?
I believe there are something like 5 boolean types in iOS environment (which comes from C, C++ and Objective C).
- _Bool
- bool
- BOOL
- boolean_t
- Boolean
And there are at least four pairs of values for them:
- true, false
- TRUE, FALSE
- YES, NO
- 1, 0
Which one do you think is the best (style wise) to use for iOS Objective C development?
Update 1
I mentioned a type “boolean”. It looks like it doesn’t exist. I removed it from the list and added _Bool.
I am aware of typedef’s for these types and values. The question is about style differences.
iOS and OS X are mostly made of Cocoa, which use the boolean type
BOOLwith valuesYES/NO.bool_BoolBOOL/usr/include/objc/objc.h.signed charin 32 bit. Values may beYES(0x01),NO(0x00), or anything in the range -127 to 128.YES/NOare defined at<Foundation/NSObjCRuntime.h>.boolin 64 bits, guaranteed to be 0 or 1.BooleanTRUE(0x01),FALSE(0x00), or anything in the range -127 to 128.boolean_t/usr/include/mach/i386/boolean.hFor non true boolean types:
Cases where one type or another makes a difference are hard to imagine. There are several cases where casting to BOOL may bite you, and some rare situations (eg: KVO converts BOOL to a NSNumber, and bool to a CFBoolean). If anything, when you consistently use BOOL, you are covered in case Apple changes its definition.