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];
}
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.