我想在函数下使用.mm文件来处理核心数据
//在头文件中
/*Saving parameters*/
NSManagedObjectModel *managedObjectModel;
NSManagedObjectContext *managedObjectContext;
NSPersistentStoreCoordinator *persistentStoreCoordinator;
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
/* 1. Check if employee exists*/
NSEntityDescription *employeeentity = [NSEntityDescription
entityForName:@"employees" inManagedObjectContext:context];
[fetchRequest setEntity:employeeentity];
NSError *error;
NSArray* employee_info = [context executeFetchRequest:fetchRequest error:&error];
if (employee_info !=nil) {
NSLog(@"employee Exist");
}
else {
NSLog(@"employee NOT Exist");
}
我使用mm因为我也使用cpp也有任何建议
祝你好运
答案 0 :(得分:1)
我根本不是C ++人。但如果我被允许做出有根据的猜测:
对我而言,听起来好像编译器不知道NSPersistentStoreCoordinator是什么
所以你应该包含标题<CoreData/CoreData.h>
或者告诉他这个类存在的C ++等价于@class NSPersistentStoreCoordinator