Skip to content

Instantly share code, notes, and snippets.

@derektu
Created March 14, 2013 01:33
Show Gist options
  • Save derektu/5158106 to your computer and use it in GitHub Desktop.
Save derektu/5158106 to your computer and use it in GitHub Desktop.
Sample code for determine the path of a resource file. Initially the resource file is shipped with the application bundle, but if user modifies it, it is saved to document folder
// TODO: pathForResource:@"Party.xml" ofType:nil should work.
// If so, then we can extract Party.xml as parameter. Better, we can add a path parameters, so that the file is stored
// to <DocumentPath>/data/<someFile>
//
+ (NSString *)dataFilePath:(BOOL)forSave {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentsPath = [documentsDirectory
stringByAppendingPathComponent:@"Party.xml"];
if (forSave ||
[[NSFileManager defaultManager] fileExistsAtPath:documentsPath]) {
return documentsPath;
} else {
return [[NSBundle mainBundle] pathForResource:@"Party" ofType:@"xml"];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment