Skip to content

Instantly share code, notes, and snippets.

@popcornylu
Created July 8, 2011 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popcornylu/1071312 to your computer and use it in GitHub Desktop.
Save popcornylu/1071312 to your computer and use it in GitHub Desktop.
[ios] Copy sqlite db from main bundle
NSString* docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString* dbPath = [docPath stringByAppendingPathComponent:@"mydatabase.db"];
NSFileManager *fm = [NSFileManager defaultManager];
// Check if the database is existed.
if(![fm fileExistsAtPath:dbPath])
{
// If database is not existed, copy from the database template in the bundle
NSString* dbTemplatePath = [[NSBundle mainBundle] pathForResource:@"mydatabase" ofType:@"db"];
NSError* error = nil;
[fm copyItemAtPath:dbTemplatePath toPath:dbPath error:&error];
if(error){
NSLog(@"can't copy db template.");
assert(false);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment