[ACCEPTED]-How to get URL for application's document directory iPhone-iphone
Accepted answer
An alternative solution would be to use 3 the -[NSFileManager URLsForDirectory:inDomains:]
method and fetching the path from the 2 returned NSArray:
Objective-C:
NSArray *paths = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask];
NSURL *documentsURL = [paths lastObject];
Swift:
let paths = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let documentsURL = paths[0] as! NSURL
This 1 is supported in iOS 4.0+
You can get the document path via the NSSearchPathForDirectoriesInDomains
foundation function as 1 follows:
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths objectAtIndex:0];
This will work on iOS 2+.
Swift 3
let documentsUrl = FileManager.default.urls(for: .documentDirectory, in:.userDomainMask).first!
0
Here is the Swift 2.2 version:
let paths = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let filePath = paths[0].URLByAppendingPathComponent("filename")
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.