我正在从服务器检索数据 - 其中使用的NS号包含数据库格式的BOOL值。但是当我尝试使用TRUE或FALSE时,它确实允许这样做。 - 我是Xcode的初学者。
for (unsigned int i =0; i<studentDashBoardDetails.count; i++) {
// Early CheckOut Days
if ([[[ studentDashBoardDetails objectAtIndex:i]objectForKey:@"dayType"]isEqualToString: @"Working"]&&[[[studentDashBoardDetails objectAtIndex:i]objectForKey:@"isAttended"]isEqualToNumber:[NSNumber numberWithInt:1]]&&[[[studentDashBoardDetails objectAtIndex:i]objectForKey:@"timeSpent"]isLessThan:@"08.00.00"])
{
NSLog(@" Early Check out on %@",[[studentDashBoardDetails objectAtIndex:i]objectForKey:@"attendanceDate"]);
答案 0 :(得分:1)
NSNumber numberWithInt
返回当前值的签名integer
,以访问可以使用NSNumber numberWithBool
方法的bool值,它会创建一个对象并返回NSNumber
,可以对其进行处理作为bool
。
我希望它能帮助您找到解决问题的正确方法
答案 1 :(得分:1)
保存时保存为NSNumber
NSNumber *isAttended = [[studentDashBoardDetails objectAtIndex:i]objectForKey:@"isAttended"];
在阅读时你会像这样做你的情况
if (isAttended.boolValue){
//true
}else{
//false
}
在你的情况下,你必须这样做
if ([[[ studentDashBoardDetails objectAtIndex:i]objectForKey:@"dayType"]isEqualToString: @"Working"] && isAttended.boolValue &&[[[studentDashBoardDetails objectAtIndex:i]objectForKey:@"timeSpent"]isLessThan:@"08.00.00"])
{
NSLog(@" Early Check out on %@",[[studentDashBoardDetails objectAtIndex:i]objectForKey:@"attendanceDate"]);
}