Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an iOS application's "~/Library" path reliably

This Apple tech note:

http://developer.apple.com/library/ios/#qa/qa2010/qa1699.html

suggests storing "internal" user documents in a subdirectory off of ~/Library. But I can't find one of the pre-created search domains that would get me this. What's the best/most correct/least likely to ever break way of constructing this path?

Thanks.

like image 807
Ben Zotto Avatar asked Sep 21 '10 17:09

Ben Zotto


2 Answers

The correct way is

NSString* path;
path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)[0];

However, [@"~/Library" stringByExpandingTildeInPath] also works.


Swift 3:

let path = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask, true)[0]
like image 141
kennytm Avatar answered Oct 22 '22 14:10

kennytm


You can also try this:

[NSHomeDirectory() stringByAppendingString:@"/Library"]
like image 35
Vidhur Avatar answered Oct 22 '22 15:10

Vidhur