I have Core Data working correctly (loading, saving) with one entity called THSettings.
However, I want to create another unrelated Core Data entity called THDetails.
When I create another entity in the same xcdatamodeld file it gives me this error when running the app: "The model used to open the store is incompatible with the one used to create the store".
So I removed that entity and created another xcdatamodeld file for the new entity and now it gives this error: "* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSFetchRequest could not locate an NSEntityDescription for entity name 'THDetails''"
Can anyone please tell me why this does not work? I should be able to save multiple unrelated entities...
Here is the code to load THDetails:
-(NSMutableArray *)loadSavedNotes {
THAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *moc = [appDelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"THDetails"];
NSMutableArray *detailsList = [[moc executeFetchRequest:fetchRequest error:nil] mutableCopy];
NSLog(@"%d", [detailsList count]);
return detailsList;
}
Here is the code to load THSettings:
THAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *moc = [appDelegate managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"THSettings"];
NSMutableArray *settingsList = [[moc executeFetchRequest:fetchRequest error:nil] mutableCopy];
// ... process it
You need to define a model that defines all your entities. If you add an additional entity to a model, you have two options:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With