How to get a `NSURL` of the document directory?
cocoa-touch, ios
Solution
You need to use a file URL to get the location of a resource on the file system.
[NSURL fileURLWithPath: documentsDirectory]
You can also use `NSFileManager` to get the same URL.
NSArray *arr = [[NSFileManager defaultManager] URLsForDirectory: NSDocumentDirectory inDomains: NSUserDomainMask];
NSURL *documentsUrl = [arr firstObject];
Problem
I have the following code: ``` +(NSURL*) getRecordingDirectory { NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* documentsDirectory = [paths objectAtIndex:0]; NSURL* url = [[NSURL alloc] initWithString:documentsDirectory]; //<-- nil return url; } ``` The line `NSURL* url = [[NSURL alloc] initWithString:documentsDirectory];` Doesn't seem to work. `url` remains `nil` after the line.