0
votes

I get the error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'CorePlaylist''

But it worked a little while ago! Now I get the error before didFinishLaunchingWithOptions is terminated.

My code is:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.
    NSLog(@"DID finish launching %@", [self managedObjectContext]);

    PlaylistsViewController *table = [[PlaylistsViewController alloc] init];

    NSManagedObjectContext *context = [self managedObjectContext];

    if (!context) {
        NSLog(@"\nCould not create *context for self");
    }

    table.context = context;

    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

    return YES;
}

EDIT:

-(void) getData {
context = [(ClientAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext]; 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"CorePlaylist" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setFetchBatchSize:20];
[request setEntity:entity];

NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"playlistid" ascending:YES];

NSArray *newArray = [NSArray arrayWithObject:sort];

[request setSortDescriptors:newArray];

NSError *error;

NSMutableArray *results = [[context executeFetchRequest:request error:&error] mutableCopy];

[self setArr:results];

[self.tableView reloadData];
}
1
This usually happens if you change your data model. If you changed it, just delete the app from the device and compile again. And if you changed the entity name, check if the one you use in code is still the same - d.ennis
I've already tried this and the error first started while I weren't working with coredata. - AlexanderN
try to clean the project too. - Lorenzo B
Wait, CorePlaylist is not an Entry? It's the name of your Model? - d.ennis
Its the entity, the name of the model is Client ;) Delete the app, clean it and rebuild but still same error - AlexanderN

1 Answers

1
votes

Make sure your coreDataModel files are in the project and the entities your are calling are correctly spelled (case sensitive).

If you are testing on your device, you may need to completly remove the application they to deploy it again to prevent corrupted database issues.