Skip to content

Instantly share code, notes, and snippets.

@dragthor
Created December 4, 2012 15:58
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 dragthor/4205461 to your computer and use it in GitHub Desktop.
Save dragthor/4205461 to your computer and use it in GitHub Desktop.
iOS get resource path for writing sqlite3 database
// Get documents directory
NSString *documentsDirectory = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex: 0];
NSString *targetPath = [documentsDirectory stringByAppendingPathComponent:@"todo.db"];
if (![[NSFileManager defaultManager] fileExistsAtPath: targetPath]) {
NSString *sourcePath = [[NSBundle mainBundle] pathForResource:@"todo" ofType:@"db"];
[[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:targetPath error:nil];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment