Note that there are some explanatory texts on larger screens.

plurals
  1. POPre-load core data database in iOS 5 with UIManagedDocument
    primarykey
    data
    text
    <p>I'm trying to come up with a way that I can pre-load data into core data while using an <code>UIManagedDocument</code>. My attempt so far is to make the document in a "Loader" app using this code.. </p> <pre><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]; }]; } </code></pre> <p>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.</p> <p>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. </p> <p>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 <code>UIManagedDocument</code> 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 <code>UIManagedDocument</code>'s <code>-(BOOL)loadFromContents:ofType:error:</code> method .. I'm not even sure this is what I should be using.</p> <p>Does anyone have an idea as to how this is normally done? Thanks! </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload