Can't get entities from loaded SQL store
Can't get entities from loaded SQL store
- Subject: Can't get entities from loaded SQL store
- From: "Ian G. Gillespie" <email@hidden>
- Date: Sun, 3 Sep 2006 11:22:37 -0400
Greetings,
I am trying to manually load in a core data SQL store from a file
that my other application writes out. Using the sample code in Core
Recipes I have been able to load the managed object model, create a
store and managed object context, but when I perform a fetch request
everything always comes back empty. If anyone has time to look at my
sample code below and let me know if they see any issues or know what
I am forgetting to do I would appreciate it.
NSArray *bundles = [NSArray arrayWithObject:[NSBundle mainBundle]];
// create the model and coordinator
//the .xcodedatamodel file is bundled in the project
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel
mergedModelFromBundles:bundles];
NSPersistentStoreCoordinator *store = [[NSPersistentStoreCoordinator
alloc] initWithManagedObjectModel: managedObjectModel];
//the url is temporarily hard coded to a test file on disk
NSError *error;
if (![store addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:url options:nil error:&error]){
[[NSApplication sharedApplication] presentError:error];
}
//no errors so far so we have our store from the file
//create a managed object context and set its store
NSManagedObjectContext *managedObjectContext =
[[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator: store];
//prepare the fetch request
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"MyEntity" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSArray *myEntities = [managedObjectContext
executeFetchRequest:request error:&error];
//this array is always empty even if I open the file in the
application that created it and see there are plenty of "MyEntities"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden