我正在尝试从我的核心数据库中获取单个对象,但是它一直返回 null。我的方法基于另一种方法,该方法返回我正在访问的 coredata 对象的每个值。
我以前从未尝试过,也尝试过阅读苹果文档,但它只是没有意义..这就是我的方法的样子
- (NSMutableArray *)readSelectedInstall:(NSString *)projIDString {
NSManagedObjectContext *context = [self managedObjectContext];
if (context == nil) {
NSLog(@"Nil");
}
else {
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"InstallProject" inManagedObjectContext:context];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ProjID==%@", projIDString];
[fetchRequest setPredicate:predicate];
NSError *error;
NSMutableArray *installProjectDictionaryArray = [[NSMutableArray alloc] init];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
for (InstallProject *installProj in fetchedObjects) {
NSMutableDictionary *tempInstallProjectDictionaryArray = [[ NSMutableDictionary alloc] init];
[tempInstallProjectDictionaryArray setObject:installProj.companyName forKey:@"CompanyName"];
[tempInstallProjectDictionaryArray setObject:installProj.projNo forKey:@"ProjNo"];
[tempInstallProjectDictionaryArray setObject:installProj.projID forKey:@"ProjID"];
[installProjectDictionaryArray addObject:tempInstallProjectDictionaryArray];
}
return installProjectDictionaryArray;
}
return nil;
}
任何帮助我返回 projID 与 projIDString 匹配的单个项目将不胜感激。