Last active
August 29, 2015 13:56
-
-
Save alekseypotapov-dev/9246581 to your computer and use it in GitHub Desktop.
Use this if you wonna to save .plist to Document directory and then wonna to edit this file
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
/* | |
Then just to use somehow like this (if array) | |
NSMutableArray *parsedPlist = [[NSMutableArray alloc] initWithContentsOfFile:[PlistReader copyFileToDocumentDirectory:%"filename.plist"]]; | |
*/ | |
+ (NSString *)copyFileToDocumentDirectory:(NSString *)fileName | |
{ | |
NSError *error; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, | |
NSUserDomainMask, | |
YES); | |
NSString *documentsDir = [paths objectAtIndex:0]; | |
NSString *documentDirPath = [documentsDir | |
stringByAppendingPathComponent:fileName]; | |
NSArray *file = [fileName componentsSeparatedByString:@"."]; | |
NSString *filePath = [[NSBundle mainBundle] | |
pathForResource:[file objectAtIndex:0] | |
ofType:[file lastObject]]; | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
BOOL success = [fileManager fileExistsAtPath:documentDirPath]; | |
if (!success) { | |
success = [fileManager copyItemAtPath:filePath | |
toPath:documentDirPath | |
error:&error]; | |
if (!success) { | |
NSAssert1(0, @"Failed to create writable txt file file with message \ | |
'%@'.", [error localizedDescription]); | |
} | |
} | |
return documentDirPath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment