Tag: nsnull

对NSManagedObject属性值进行NSNull处理

我为我的NSManagedObject属性设置值,这些值来自NSDictionary正确序列化从JSON文件。 我的问题是,当某些值是[NSNull null] ,我不能直接分配给属性: fight.winnerID = [dict objectForKey:@"winner"]; 这将抛出一个NSInvalidArgumentException "winnerID"; desired type = NSString; given type = NSNull; value = <null>; 我可以很容易地检查[NSNull null]的值,并分配nil : fight.winnerID = [dict objectForKey:@"winner"] == [NSNull null] ? nil : [dict objectForKey:@"winner"]; 但是我认为这不是很高雅,而且有很多属性需要设置。 而且,当处理NSNumber属性时,这变得更加困难: fight.round = [NSNumber numberWithUnsignedInteger:[[dict valueForKey:@"round"] unsignedIntegerValue]] NSInvalidArgumentException现在是: [NSNull unsignedIntegerValue]: unrecognized selector sent to instance 在这种情况下,我必须先处理[dict valueForKey:@"round"]然后再创build它的NSUInteger值。 而一线解决scheme不见了。 […]

在NSDictionary中检测一个Null值

我有一个从API服务器的JSON响应填充的NSDictionary 。 有时这个字典中的键的值是Null 我正在尝试将给定的值放到表格单元格的细节文本中进行显示。 问题是,当我试图强制NSString的价值,我得到一个崩溃,我认为是因为我试图强制Null到一个string。 什么是正确的方法来做到这一点? 我想要做的是这样的: cell.detailTextLabel.text = sensor.objectForKey( "latestValue" ) as NSString 这里是一个字典的例子: Printing description of sensor: { "created_at" = "2012-10-10T22:19:50.501-07:00"; desc = "<null>"; id = 2; "latest_value" = "<null>"; name = "AC Vent Temp"; "sensor_type" = temp; slug = "ac-vent-temp"; "updated_at" = "2013-11-17T15:34:27.495-07:00"; } 如果我只是需要在条件中包装所有这一切,那很好。 我只是无法弄清楚有什么条件。 回到Objective-C世界,我会比较[NSNull null]但似乎并没有在Swift中工作。

和nil有什么区别?

以下是我所见的情况: NSMutableArray *controllers = [[NSMutableArray alloc] init]; for (unsigned i = 0; i < kNumberOfPages; i++) { [controllers addObject:[NSNull null]]; } 为什么不在那个地方?

如何检测NSString是否为空?

我有一段代码,检测NSString是NULL , nil等,但是,它崩溃。 这是我的代码: NSArray *resultstwo = [database executeQuery:@"SELECT * FROM processes WHERE ready='yes' LIMIT 0,1"]; for (NSDictionary *rowtwo in resultstwo) { NSString *getCaption = [rowtwo valueForKey:@"caption"]; if (getCaption == NULL) { theCaption = @"Photo uploaded…"; } else if (getCaption == nil) { theCaption = @"Photo uploaded…"; } else if ([getCaption isEqualToString:@""]) { theCaption = […]

我如何检查NSArray中的对象是否是NSNull?

我得到一个空值的数组。 请检查我的数组结构: ( "< null>" ) 当我试图访问索引0因为崩溃 -[NSNull isEqualToString:]: unrecognized selector sent to instance 0x389cea70 目前由于该数组崩溃而崩溃: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x389cea70' *** First throw call stack: (0x2d9fdf53 0x3820a6af 0x2da018e7 0x2da001d3 0x2d94f598 0x1dee57 0x1dfd31 0x302f598d 0x301a03e3 0x3052aeed 0x3016728b 0x301659d3 0x3019ec41 0x3019e5e7 0x30173a25 0x30172221 0x2d9c918b […]

什么时候应该在Objective-C中使用nil和NULL?

这是示例代码: NSDictionary *myDictionary = [NSDictionary dictionary]; NSNumber *myNumber = [myDictionary valueForKey: @"MyNumber"]; NSLog(@"myNumber = %@", myNumber); // output myNumber = (null) if (myNumber == nil) NSLog(@"test 1 myNumber == nil"); if (myNumber == NULL) NSLog(@"test 2 myNumber == NULL"); if ([myNumber isEqual:[NSNull null]]) NSLog(@"test 3 myNumber == [NSNull null]"); 什么时候应该使用nil,NULL和[NSNull null]?

Objective-C中nil,NIL和null之间的区别

我想知道nil , NIL和null之间的区别。 我search了一下,发现这个: nil – >指向Objective-C对象的空指针 NIL – >指向Objective-C类的空指针 null – > null指向原始types或不存在数据的指针 但是我无法清楚地理解“Objective-C对象”和“类”这两个术语。 请给我解释一下。 另外,Objective-C中是否有像NSNull或NSNil这样的NSNull ? 如果是这样,那么请解释它是什么。