Created
September 18, 2011 15:42
-
-
Save rsaunders100/1225177 to your computer and use it in GitHub Desktop.
(iOS) Commands to save and load & copy from from the bundle and the documents directory.
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
+ (NSString*) pathForSaving | |
{ | |
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString* documentsDirectory = [paths objectAtIndex:0]; | |
return [documentsDirectory stringByAppendingPathComponent:@"fileName.plist"]; | |
} | |
+ (void) loadFromDisk { | |
NSString* path = [MyClass pathForSaving]; | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
// If file dose not exist copy it from the bundle | |
if (![fileManager fileExistsAtPath:path]) | |
{ | |
NSString* bundlePath = [[NSBundle mainBundle] pathForResource:@"fileName" | |
ofType:@"plist"]; | |
[fileManager copyItemAtPath:bundlePath | |
toPath:path | |
error:nil]; | |
} | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment