The correct way to retrieve the path of the documents directory in iOS is, according to Apple Documentation:
1 2 3 4 5 6 |
NSArray *arrayPaths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDir = [arrayPaths objectAtIndex:0]; |
I never seem to be able to remember this when I need it. So I wrapped this and other directory related routines into a simple Objective-C class. Here’s what the interface looks like (I’ve removed the doxygen documentation for brevity):
1 2 3 4 5 6 7 |
@interface IDZDirectories : NSObject { } + (NSString*)documents; + (NSString*)home; + (NSString*)cache; + (NSString*)temporary; @end |
A simple usage example would be:
1 2 |
NSString* docs = [IDZDirectories documents]; NSString* filename = [docs stringByAppendingPathComponent:@"MyFileName.txt"]; |
Now this is not an earth-shattering piece of code, but it may save you some typing. You are free to download it and use it in your own projects.
Download
IDZDirectories.zip