Skip to content

Instantly share code, notes, and snippets.

@wisaruthk
Last active August 29, 2015 13:57
Show Gist options
  • Save wisaruthk/9433526 to your computer and use it in GitHub Desktop.
Save wisaruthk/9433526 to your computer and use it in GitHub Desktop.
Path Example, Documents, Bundle
#pragma mark - Defind Functions
- (void)copyBundleToDocuments{
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
//Document path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
NSString *docDBPath = [docDir stringByAppendingPathComponent:@"database.sqlite"];
NSLog(@"docDBPath %@",docDBPath); //print xxx/Documents/database.sqlite
if([fileManager fileExistsAtPath:appDBPath]){
return;
}
//Bundle resource
NSString *bundleDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"database.sqlite"];
NSLog(@"bundlePath %@",bundleDBPath); //print xxx/Myapp1.app/database.sqlite
success = [fileManager copyItemAtPath:defaultDBPath toPath:appDBPath error:&error];
if(!success){
NSAssert1(0,@"Failed to create file with message '%@'.",[error localizedDescription]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment