Created
March 14, 2013 01:33
-
-
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
This file contains 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
// 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