Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#import <Foundation/Foundation.h>
@interface FileHelper : NSObject
+(NSString *) getDataFilePath;
+(NSString *) getConfigFilePath;
+(NSString *) getPlistFilePathWithName:(NSString *)name;
+(BOOL) removeFileAtPath:(NSString *)path;
#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];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment