I believe there is a difference between bool
and BOOL
, check out this webpage for an explanation of why:
http://iosdevelopertips.com/objective-c/of-bool-and-yes.html
Because BOOL
is an unsigned char
rather than a primitive type, variables of type BOOL
can contain values other than YES
and NO
.
Consider this code:
BOOL b = 42;
if (b) {
printf("b is not NO!
");
}
if (b != YES) {
printf("b is not YES!
");
}
The output is:
b is not NO!
b is not YES!
For most people this is an unnecessary concern, but if you really want a boolean it is better to use a bool
. I should add: the iOS SDK generally uses BOOL
on its interface definitions, so that is an argument to stick with BOOL
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…