在 plist 中设置为 false 的布尔值结果为 true
Boolean value set to false in plist is coming out as true
我在 plist 中有一个布尔值:
当作为来源查看时,它看起来像:
它的读作:
NSDictionary* configPlist = [[NSBundle mainBundle]pathForResource:@"Config" ofType:@"plist"];
BOOL shouldBeFalse = configPlist[@"WhyIsThisReturningTrue"];
但是当代码被读取时 shouldBeFalse 是 YES。
在调试器 configPlist 中,这个值为 NO:
为什么当代码为 运行 时 shouldBeFalse 设置为 YES?
这是因为您引用的是 NSNumber
指针,而不是值。有点类似于做
NSNumber * b = [NSNumber numberWithBool:NO];
if ( b )
{
NSLog(@"This should fire, b is not nil" );
}
if ( b.boolValue )
{
NSLog(@"This should NOT fire, b's value is NO" );
}
所以只需将其更改为例如[configPlist[@"WhyIsThisReturningTrue"] boolValue]
我在 plist 中有一个布尔值:
当作为来源查看时,它看起来像:
它的读作:
NSDictionary* configPlist = [[NSBundle mainBundle]pathForResource:@"Config" ofType:@"plist"];
BOOL shouldBeFalse = configPlist[@"WhyIsThisReturningTrue"];
但是当代码被读取时 shouldBeFalse 是 YES。
在调试器 configPlist 中,这个值为 NO:
为什么当代码为 运行 时 shouldBeFalse 设置为 YES?
这是因为您引用的是 NSNumber
指针,而不是值。有点类似于做
NSNumber * b = [NSNumber numberWithBool:NO];
if ( b )
{
NSLog(@"This should fire, b is not nil" );
}
if ( b.boolValue )
{
NSLog(@"This should NOT fire, b's value is NO" );
}
所以只需将其更改为例如[configPlist[@"WhyIsThisReturningTrue"] boolValue]