我有以下CoreDataModel:
每个公园都与一组检查有关,每次检查都与公园成反比。我正在从Web服务响应中将数据加载到园区中。因此,从Park的NSManagedObject子类内部,我需要查询具有特定inspectionID
和assigmentID
的所有相关检查(只有一个满足该条件)并创建它(如果不存在),我使用了以下功能:
- (Inspection *)getInspectionWithId:(NSInteger)inspectionId assignmentId:(NSInteger)assignmentId {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
//Crash in the following line
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY (self.inspections.inspectionID == %d AND self.inspections.assignmentID == %d)", inspectionId, assignmentId];
[fetchRequest setPredicate:predicate];
NSError *error = nil;
NSArray *array = [[[Model sharedModel] managedObjectContext] executeFetchRequest:fetchRequest error:&error];
if (array == nil || array.count < 1) {
NSEntityDescription *inspectionEntity = [NSEntityDescription entityForName:@"Inspection" inManagedObjectContext:[[Model sharedModel] managedObjectContext]];
return (Inspection *)[[NSManagedObject alloc] initWithEntity:inspectionEntity insertIntoManagedObjectContext:[[Model sharedModel] managedObjectContext]];
}
else {
return (Inspection *)array[0];
}
}
但该应用程序崩溃时出现以下异常。我不确定谓词中的条件是否适用于此。有人可以帮忙吗?
由于未捕获的异常而终止应用 'NSInvalidArgumentException',原因:'无法解析格式 字符串“ANY(self.inspections.inspectionID ==%d AND self.inspections.assignmentID ==%d)“'