Reputation: 10045
Just got a -1 for my answer on how to get the documents directory. I always do it like this:
NSString *documentsPath = [@"~/Documents" stringByExpandingTildeInPath];
And it always works as I expect it to. Are there any real underwater rocks with this method?
Upvotes: 0
Views: 756
Reputation: 498
Right method to call: NSSearchPathForDirectoriesInDomains()
As Apple documentation states:
Creates a list of path strings for the specified directories in the specified domains. The list is in the order in which you should search the directories. If expandTilde is YES, tildes are expanded as described in stringByExpandingTildeInPath.
Example:
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
Upvotes: 0
Reputation: 20366
No, it does NOT always work. If your app is running in sandbox (which is required by the app store), you won't be able to get the real documents directory.
I just did some test and below is what I got:
/Users/<user-name>/Library/Containers/<app-name>/Data/Documents
But my real document foder is
/Users/<user-name>/Documents
Upvotes: 1