my program needs to take a prepopulated sql database and then save the records to the app’s database. Unfortunately for some reason the application quits in this method in the application delegate:
#pragma mark -
#pragma mark Core Data stack
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSString *modelPath = [[NSBundle mainBundle] pathForResource:@"iProspectLite" ofType:@"sqlite"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}
it seems as if the application cannot find a valid managedObjectModel_, or it doesn’t exist, or is not creating one. How do i solve this?
one of the error messages I get on the console is this:
Terminating app due to uncaught exception reason: [NSKeyedUnarchiver initForReadingWithData:]
part of this I have narrowed down to the NSManagedObject, in that there doesn’t seem to be one created or found.
Other information that may be helpful:
I added an entity and defined attributes as described in many other core-data tutorials
the following is the class that defines my entity:
#import "Mine.h"
@implementation Mine
@dynamic primarykey;
@dynamic name;
@dynamic firstCommodity;
@dynamic longitude;
@dynamic county;
@dynamic secondCommodity;
@dynamic latitude;
@dynamic thirdCommodity;
@end
You problem is that your trying to load your model file from the path to an SQL persistent store inside the app bundle. Stores and model files are two separate types of files with two separate functions. You can’t initialize a NSManagedObjectModel instance from an SQL file and vice versa because the two file types hold completely different information.
You need to change the
pathForResource:to look for the right file. The file type ismomand the default name is the app name so you should use something like:(If you named you model something else, use that name.)
All this has nothing to do with importing an existing SQL file. However, you will need to fix this before importing the SQL as other’s have suggested.