0

I have an ipad app using core data in which the data store is preloaded on first load. Today i needed to make some changes in the database and after doing so, my code that loads the datastore does not find the resource. I have copied the resource into the project directory and verified that it does exist and is spelled properly. Here is the code that loads the DB

NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"SpokeCalcMD.sqlite"];
if(![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]){

    //fails at this line
    NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SpokeCalcMD" ofType:@"sqlite"]];

    NSLog(@"PRELOAD URL: %@", preloadURL);
    NSError *err = nil;
    if(![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err]){
        NSLog(@"FAILED TO COPY DATABASE");
    }
}

Produces the following:

ERROR: 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'

I have taken all the normal steps, project clean, reset simulator. Any suggestions? Thanks!

Pheepster
  • 6,045
  • 6
  • 41
  • 75
  • When you crack open the app bundle is the sqlite file there? Is it by chance in a different directory? – Marcus S. Zarra Jun 11 '14 at 19:01
  • Also make sure your ˋSpokeCalcMD.sqliteˋ file has been included as a project resource in Xcode. – Romain Jun 11 '14 at 20:23
  • And check that your database file has indeed been included in the project by Xcode with a valid extension ; see here: http://stackoverflow.com/questions/12309828/ios-copy-sqlite-to-bundle-for-coredata?rq=1 – Romain Jun 11 '14 at 20:25

0 Answers0