"NSNumber numberWithInt" 在 Xcode 中有什么用

What is the Use of "NSNumber numberWithInt" in Xcode

我正在从服务器检索数据 - 其中使用的 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"]);

NSNumber numberWithInt returns 带符号的 integer 当前值,要访问 bool 值你可以使用 NSNumber numberWithBool 方法,它创建一个对象和 returns NSNumber 可以视为 bool

我希望它能帮助您找到解决问题的正确方法

保存时像这样另存为 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"]);
}