说明:Ojbective-C中把BOOL定义成无符号字符型,这意味着BOOL类型
的值远不止YES(1)或
NO(0),所以,不要直接将BOOL值与YES进行比较。
示例-1:BOOL a = 2.5;
if (a == YES) {
NSLog(@"a == yes"); }
else if(a == NO){
NSLog(@"a == no"); }
else
{NSLog(@"a == other");
}NSLog(@"a+0.5 = %f",a+0.5);iOS编程规范v1.0
==========2014-04-07 21:56:14.280 2014-04-07 21:56:14.281示例-2:BOOL a =130;
if (a == YES) {
NSLog(@"a == yes"); }
else if(a == NO){
NSLog(@"a == no"); }
else
{NSLog(@"a == other");
test[1224:907] a == other test[1224:907] a+0.5 = 2.500000
}NSLog(@"a=%hhd a+0.5 = %f",a,a+0.5);==========2014-04-07 22:14:07.986
test[1510:907] a == other2014-04-07 22:14:07.988 test[1510:907] a=-126 a+0.5 =
-125.500000