Error copying file from app bundle

Posted by Michael Chen on Stack Overflow See other posts from Stack Overflow or by Michael Chen
Published on 2014-08-20T06:50:06Z Indexed on 2014/08/23 22:21 UTC
Read the original article Hit count: 244

Filed under:
|
|
|

I used the FireFox add-on SQLite Manager, created a database, which saved to my desktop as "DB.sqlite". I copied the file into my supporting files for the project. But when I run the app, immediately I get the error "Assertion failure in -[AppDelegate copyDatabaseIfNeeded], /Users/Mac/Desktop/Note/Note/AppDelegate.m:32 2014-08-19 23:38:02.830 Note[28309:60b] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to create writable database file with message 'The operation couldn’t be completed. (Cocoa error 4.)'.' First throw call stack: "...

Here is the App Delegate Code where the error takes place

-(void) copyDatabaseIfNeeded
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSString *dbPath = [self getDBPath];
BOOL success = [fileManager fileExistsAtPath:dbPath];

if (!success)
{
    NSString *defaultDBPath = [[ [NSBundle mainBundle
                                   ] resourcePath] stringByAppendingPathComponent:@"DB.sqlite"];
    success = [fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
    if (!success)
        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);

}
}

I am very new to Sqlite, so I maybe I didn't create a database correctly in the FireFox Sqlite manager, or maybe I didn't "properly" copy the .sqlite file in? (I did check the target membership in the sqlite and it correctly has my project selected. Also, the .sqlite file names all match up perfectly.)

© Stack Overflow or respective owner

Related posts about ios

Related posts about objective-c