Skip to content

@NicosKaralis /FileHelper.h
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
FileHelper
#import <Foundation/Foundation.h>
@interface FileHelper : NSObject
+(NSString *) getDataFilePath;
+(NSString *) getConfigFilePath;
+(NSString *) getPlistFilePathWithName:(NSString *)name;
+(BOOL) removeFileAtPath:(NSString *)path;
@end
#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
Something went wrong with that request. Please try again.