Last active
August 29, 2015 13:57
-
-
Save wisaruthk/9433526 to your computer and use it in GitHub Desktop.
Path Example, Documents, Bundle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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