insertNewObjectForEntityForName:

The fact that you didn’t set up the MOC is almost certainly the problem. Most specifically, it means you’re probably not loading your MOM (Managed Object Model) that defines Person. Somewhere in your code you should have something like this:

managedObjectModel = [[NSManagedObjectModel mergedModelFromBundles:nil] retain];    

And something like this:

persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

And something like this:

NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil) {
    managedObjectContext = [[NSManagedObjectContext alloc] init];
    [managedObjectContext setPersistentStoreCoordinator: coordinator];

I’m just copying lines out of the AppDelegate of the Core Data template (what you get if you make a new application that uses Core Data).

If you have all that, make sure that your xcdatamodel is listed in your Compile Sources step of the build. And of course make sure that Person is actually the Entity name in your xcdatamodel. Entity name is not the same as Class, though they are often set to be the same.

Leave a Comment