Search code examples
xcodecore-dataobjective-c++

ISO C++ forbids declaration of 'NSPersistentStoreCoordinator' with no type


I have .mm file that I want under function to work with core data

// in header file

/*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");

}

I use mm because I work with cpp also any suggestion please

Best regards


Solution

  • I am not a C++ guy at all. But if I'm allowed to make an educated guess:

    For me it sounds like the compiler does not know what NSPersistentStoreCoordinator is.
    So you should include the header <CoreData/CoreData.h> or tell him that this class exists with the C++ equivalent of @class NSPersistentStoreCoordinator