在这里,我使用NSManagedObject
.
第一个问题是,当我尝试将空值分配给属性时,它给出了错误:
desired type = NSString;
给定类型 =null。
我NSDictionary
从 JSON 文件序列化中获取值。但是当值为空时,我得到了崩溃,给出了上述错误:
desired type = NSString;
给定类型 =null。
为此,我正在编写以下代码,但仍然出现错误。我应该怎么做才能正确处理空值。
NSManagedObject *updateDevice=[results lastObject];
if([results count] > 0){
//if(1){
NSLog(@"updateeeee");
//continue;
[updateDevice setValue:[NSString stringWithFormat:@"%@",[dict objectForKey:@"clip_image_path"]] forKey:@"clip_image_path"];
[updateDevice setValue:[dict objectForKey:@"clip_name"] forKey:@"clip_name"];
[updateDevice setValue:[dict objectForKey:@"page_categorisation"] forKey:@"page_categorisation"];
以下属性具有空值
[updateDevice setValue:[dict objectForKey:@"personality_company_master_values"] == [NSNull null] ? nil:dict forKey:@"personality_company_master_values"];
[updateDevice setValue:[dict objectForKey:@"category_master_values"] == [NSNull null] ? nil: dict forKey:@"category_master_values"];
[updateDevice setValue:[dict objectForKey:@"brand_master_values"] == [NSNull null] ? nil:dict forKey:@"brand_master_values"];
[updateDevice setValue:[dict objectForKey:@"company_master_values"] == [NSNull null] ? nil:dict forKey:@"company_master_values"];
[updateDevice setValue:[dict objectForKey:@"product_master_values"] == [NSNull null] ? nil:dict forKey:@"product_master_values"];
[updateDevice setValue:[dict objectForKey:@"industry_master_values"] == [NSNull null] ? nil:dict forKey:@"industry_master_values"];