Skip to content

Instantly share code, notes, and snippets.

@derektu
Created February 12, 2013 03:23
Show Gist options
  • Save derektu/4760007 to your computer and use it in GitHub Desktop.
Save derektu/4760007 to your computer and use it in GitHub Desktop.
Provide Documents path related API
#import <Foundation/Foundation.h>
// Provides Path undrer "Documents"
//
@interface DocumentPathBuilder : NSObject
@property (nonatomic, copy, readonly) NSString* documentFolder;
// Given a 'relative' filePath, return its absolute path under documents folder
//
- (NSString*) getFullPath:(NSString*)filePath;
@end
#import "DocumentPathBuilder.h"
- (id)init
{
self = [super init];
if (self)
{
// initialize document folder property
_documentFolder = [self getDocumentFolder];
}
return self;
}
- (NSString*)getDocumentFolder
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return paths[0];
}
- (NSString*)getFullPath:(NSString*)filePath
{
return [self.documentFolder stringByAppendingPathComponent:filePath];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment