关于String转BOOL的官方解释,具体示例如下:
Skips initial space characters (whitespaceSet), or optional -/+ sign followed by zeroes. Returns YES on encountering one of "Y", "y", "T", "t", or a digit 1-9. It ignores any trailing characters.(其中红色部分没有示例出来,请有了解的同学们补充)
NSDictionary *dic = @{@"d" : [NSNull null]};
BOOL a1 = [@"" boolValue];//NO
BOOL a2 = [@" " boolValue];//NO
BOOL a3 = [@" 1 " boolValue];//YES
BOOL a4 = [@"a" boolValue];//NO
BOOL a5 = [@"t" boolValue];//YES
BOOL a6 = [@"Y" boolValue];//YES
BOOL a7 = [@"+0" boolValue];//NO
BOOL a8 = [@"0" boolValue];//NO
BOOL a9 = [@"0+" boolValue];//NO
BOOL a0 = [@"y+" boolValue];//YES
BOOL a10 = [@"+y" boolValue];//NO
BOOL a11 = [@"ay" boolValue];//NO
BOOL a12 = [@"ya" boolValue];//YES
BOOL a13 = [@"1a" boolValue];//YES
BOOL a14 = [@"a1" boolValue];//NO
BOOL a15 = [@"+0y" boolValue];//NO
BOOL a16 = [@"0+y" boolValue];//NO
BOOL a17 = [[dic objectForKey:@"c"] boolValue];//nill NO
// BOOL a18 = [[dic objectForKey:@"d"] boolValue];//Crash
BOOL a18 = [@(0) boolValue];//NO
BOOL a19 = [@(9) boolValue];//YES
BOOL a20 = [@(-1) boolValue];//YES
BOOL a21 = [@(+1) boolValue];//YES
BOOL a22 = [@(-0) boolValue];//NO
BOOL a23 = [@(+0) boolValue];//NO
BOOL a24 = @(0);//YES
BOOL a25 = @(1);//YES
BOOL a26 = @"";//YES
BOOL a27 = nil;//NO
BOOL a28 = 0;//NO
BOOL a29 = 1;//YES
BOOL a30 = [NSNull null];//YES
BOOL a31 = @{};//YES
BOOL a32 = @{};//YES