Ios 检查CoreData实体的属性是否为空?
我想检查核心数据实体上的属性是否为Null。我尝试了几种方法,问了一些问题,但令人惊讶的是,没有答案,或者根本不起作用。问题提到了检查属性值的所有可能方法,但没有有效的输入。当我尝试检查属性的Ios 检查CoreData实体的属性是否为空?,ios,objective-c,core-data,Ios,Objective C,Core Data,我想检查核心数据实体上的属性是否为Null。我尝试了几种方法,问了一些问题,但令人惊讶的是,没有答案,或者根本不起作用。问题提到了检查属性值的所有可能方法,但没有有效的输入。当我尝试检查属性的Null值时,我的应用程序崩溃。任何帮助都将不胜感激。多谢各位 编辑 因此,如果联系人没有名字,我的应用程序将崩溃。请以这种方式检查 if([contact valueForKey:@"first_name"]) { ........code here } else { //Handle issue h
Null
值时,我的应用程序崩溃。任何帮助都将不胜感激。多谢各位
编辑
因此,如果联系人没有名字,我的应用程序将崩溃。请以这种方式检查
if([contact valueForKey:@"first_name"])
{ ........code here }
else
{ //Handle issue here
}
希望这能有所帮助。首先,您需要调用您的核心数据
实体
,如下所示
NSManagedObjectContext *moc = self.appDelegate.managedObjectContext;
NSFetchRequest *theRequest = [NSFetchRequest fetchRequestWithEntityName:@"Your Entity Name"];
NSError *error = nil;
NSArray *resultArray = [moc executeFetchRequest:theRequest error:&error];
if (!resultArray) {
abort();
//check here where the array is null or not
}
else
{
//then in here you can check the objects one by one
for (yourEntity *entity in resultArray)
{
NSString *myobject = entity.first_name;
//in here your can check the each object is null or not
if([myobject iseEqualToString:@""])
{
NSLog(@"the object is null");
}
}
}
好的..您能出示您的代码吗?请以这种方式检查([联系valueForKey:@“first_name”]){…….code here}或者{//Handle issue here}完成。在回答中加上。
NSManagedObjectContext *moc = self.appDelegate.managedObjectContext;
NSFetchRequest *theRequest = [NSFetchRequest fetchRequestWithEntityName:@"Your Entity Name"];
NSError *error = nil;
NSArray *resultArray = [moc executeFetchRequest:theRequest error:&error];
if (!resultArray) {
abort();
//check here where the array is null or not
}
else
{
//then in here you can check the objects one by one
for (yourEntity *entity in resultArray)
{
NSString *myobject = entity.first_name;
//in here your can check the each object is null or not
if([myobject iseEqualToString:@""])
{
NSLog(@"the object is null");
}
}
}