I'm trying to come up with a way that I can pre-load data into core data while using an UIManagedDocument. My attempt so far is to make the document in a "Loader" app using this code..
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:@"Default Database"];
if(![[NSFileManager defaultManager] fileExistsAtPath:[self.document.fileURL path]]){
[self.document saveToURL:self.document.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success){
if(success)[self loadDataIntoDocument];
}];
}
and then copy the persistentStore file from the 'documents' directory that is created in the simulator's directory to the resources section in Xcode for the main app that will be using the loaded database.
My problem is that I can't figure out how to copy that document from the app bundle and use it as a document successfully.
I've tried copying the document directory as-is from the app bundle and trying to access it as a document which gave the error that UIManagedDocument can only access a package of files.
I've tried creating another fresh document in the main app and copying the persistentStore from the bundle over the one that is created in the document with the same error.
And I've tried using UIManagedDocument's -(BOOL)loadFromContents:ofType:error: method .. I'm not even sure this is what I should be using.
Does anyone have an idea as to how this is normally done? Thanks!
