Hi there,
I'm trying to write two applications (iphone and desktop) to achieve what's been described in the following link:
core-data-is-it-possible-to-build-a-desktop-app-to-create-the-data-model-for-an
Ok. So I've created a very simple desktop app the has a single entity named Client with a string attribute field called name. I've also generated the corresponding Model class.
I've run the app added a couple of client names to the list and saved the file (as Testing.sqlite).
Now in my equivalent iphone app I'm attempting to load the file. I've generated the app initially using one of the application templates and included Core Data. NB: I've mirrored the Client entity and generated the corresponding Model class.
I've gone into my "application delegate" class and amended the persistentStoreCoordinator method to reference my "Testing.sqlite" file i.e.
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"Testing.sqlite"]];
I've also copied the saved desktop app file into the expected location i.e.
~/Library/Application Support/IPhone Simulator/User/... etc.
So now in theory at least each of the two apps should be the same.
However when I'm attempting to load the data from the it always seems to be empty. My code looks a little like this:
// fetch the delegate.
TestingAppDelegate *app = (TestingAppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext *managedObjectContext = [app managedObjectContext];
// construct the request.
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Client" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
// execute the request.
NSError *error;
NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];
if (results == nil) {
// Handle the error.
NSLog(@"No data loaded");
}
NSLog(@"Returned: %@", results);
// finally release
[results release];
[request release];
I can't seem to figure out what's going wrong. Any tips or suggestions would be totally appreciated.
When I've looked at the instance of the persistanceStoreCoordinator, managedObjectContext, resulting array (NSArray) whilst debugging I can see that it seems to contain 0 records for all of these. So I'm confused.
NB: The Testing.sqlite file contains entries.
Thanks in advance, Matt