Skip to content

Instantly share code, notes, and snippets.

@flipjorge
Created June 8, 2012 21:18
Show Gist options
  • Save flipjorge/2898166 to your computer and use it in GitHub Desktop.
Save flipjorge/2898166 to your computer and use it in GitHub Desktop.
iOS Directories paths helper
#import <Foundation/Foundation.h>
@interface Directory : NSObject
+(NSString*)documents;
+(NSString*)temp;
+(NSString*)library;
+(NSString*)bundle;
+(NSString*)cache;
+(NSString*)preferences;
@end
#import "Directory.h"
@implementation Directory
+(NSString*)documents
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
return path;
}
+(NSString*)temp
{
return NSTemporaryDirectory();
}
+(NSString*)library
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
return path;
}
+(NSString*)bundle
{
return [[NSBundle mainBundle] bundlePath];
}
+(NSString*)cache
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
return path;
}
+(NSString*)preferences
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSPreferencePanesDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
return path;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment