App 中常用的目录有6个,分别是:
(1)Home
(2)Home > Documents
(3)Home > Library
(4)Home > Library > Caches
(5)Home > Library > PReferences
(6)Home > tmp
那么如何获取这些目录呢?
1 /// Home 2 NSString *homeDir = NSHomeDirectory(); 3 4 /// Home > Documents 5 NSString *documentsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]; 6 7 /// Home > Library 8 NSString *libraryDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject]; 9 10 /// Home > Library > Caches11 NSString *cachesDir = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject];12 13 /// Home > tmp14 NSString *tmpDir = NSTemporaryDirectory();
PS:Preferences 没有相对应的取目录方法,因为该目录主要存储用户偏好设置信息,可以直接通过键值对进行读写访问,因此也不需要获取目录。
新闻热点
疑难解答