Created
July 11, 2012 12:17
-
-
Save NicosKaralis/3090009 to your computer and use it in GitHub Desktop.
FileHelper
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
#import <Foundation/Foundation.h> | |
@interface FileHelper : NSObject | |
+(NSString *) getDataFilePath; | |
+(NSString *) getConfigFilePath; | |
+(NSString *) getPlistFilePathWithName:(NSString *)name; | |
+(BOOL) removeFileAtPath:(NSString *)path; | |
@end |
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
#import "FileHelper.h" | |
#define DataFile @"data" | |
#define ConfigFile @"config" | |
@implementation FileHelper | |
+(NSString *) getDataFilePath { | |
return [self getPlistFilePathWithName:DataFile]; | |
} | |
+(NSString *) getConfigFilePath { | |
return [self getPlistFilePathWithName:ConfigFile]; | |
} | |
+(NSString *) getPlistFilePathWithName:(NSString *)name { | |
NSError *error; | |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
NSString *documentsDirectory = [paths objectAtIndex:0]; | |
NSString *path = [documentsDirectory stringByAppendingPathComponent:[name stringByAppendingPathExtension:@"plist"]]; | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
if (![fileManager fileExistsAtPath: path]) { | |
NSString *bundle = [[NSBundle mainBundle] pathForResource:name ofType:@"plist"]; | |
[fileManager copyItemAtPath:bundle toPath: path error:&error]; | |
} | |
return path; | |
} | |
+(BOOL) removeFileAtPath:(NSString *)path { | |
NSError *error; | |
NSFileManager *filemgr = [NSFileManager defaultManager]; | |
return [filemgr removeItemAtPath:path error:&error]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment