Reputation:
I am new to Core-Data so please help me with this. i have this exception
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an entity named 'ModelForProfile' in this model.'
Although i searched almost all the answers available on internet and browsed the links available on stack but nothing seems to be understanding to me.
I have A few(5-7) different view's and a save button on each view. 1.) I am using Core-Data To save Data.MI doing right thing ?? 2.) I need to have different Models for each View ?? 3.) Initially i had an exception and when i browsed the web came to know that i need to change following method a bit
- (NSManagedObjectModel *)managedObjectModel
{
if (__managedObjectModel != nil) {
return __managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"saveButtonForBasicInfo" withExtension:@"momd"];
//NSURL *modelURL1 = [[NSBundle mainBundle] URLForResource:@"saveButtonForProfile" withExtension:@"momd"];
__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
// __managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL1];
return __managedObjectModel;
}
Where " saveButtonForBasicInfo " is xcDataModel for the first model(First View).
and it worked perfect. But when this error occurred I tried adding a couple to more lines. If you could see the commented lines.
Please Help me with this. As I am a bit confused .
Thank You,
Best Regards.
Upvotes: 0
Views: 78
Reputation: 80271
Some basic concepts:
You typically only have one NSManagedObjectModel in your app. It describes your entities (something like objects) and their attributes (something like properties).
This model is initialized at app launch, you should not have to revisit it. This usually happens in the AppDelegate setting up the "Core Data Stack" which also includes the NSManagedObjectContext and the NSManagedObjectStoreCoordinator.
Each of your views should use the NSManagedObjectContext to access the model and its data. Your suggestion that you need different models for different views is way off.
You should name your various things in a meaningful way. "saveButtonForBasicInfo" is not a meaningful name for a model. Call it something like "Widgets".
Similarly an entity should be something like "User", "Appointment", "Project", "Location", "Class", etc., i.e. something that represents something real. "ModelForProfile" is a very unsuitable entity name.
Upvotes: 1