Skip to content

Instantly share code, notes, and snippets.

@rsaunders100
Created September 18, 2011 15:42
Show Gist options
  • Save rsaunders100/1225177 to your computer and use it in GitHub Desktop.
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.
+ (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