1.Home 目录.整个应用程序所在目录
let homedDirectory = NSHomeDirectory()
-
依据路径寻找过去,模拟器目录下内容如下
- 真机目录寻找
参考这里
2.Document 目录
//方法一
let documentPaths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .allDomainsMask, true)
let documentPath = documentPaths.first ?? ""
//方法二
let documentPath2 = NSHomeDirectory() + "/Documents"
print(documentPath2)// /Users/kehaoran/Library/Developer/CoreSimulator/Devices/62FD8F53-9E45-4714-A7A1-890E85E184CE/data/Containers/Data/Application/A28238F8-2935-4032-9189-C7DDFFD9FDEB/Documents
print(documentPath)// /Users/kehaoran/Library/Developer/CoreSimulator/Devices/62FD8F53-9E45-4714-A7A1-890E85E184CE/data/Containers/Data/Application/A28238F8-2935-4032-9189-C7DDFFD9FDEB/Documents
3.Library 目录
let documentPaths = NSSearchPathForDirectoriesInDomains(.libraryDirectory, .allDomainsMask, true)
结果都是数组,根据不同的 Domain 结果不同
allDomainsMask
枚举下的结果是三个元素的数组
["/Users/kehaoran/Library/Developer/CoreSimulator/Devices/62FD8F53-9E45-4714-A7A1-890E85E184CE/data/Containers/Data/Application/27D3A1C8-F52E-4E3F-9A62-ABE53F89CF72/Library", "/Library", "/Network/Library", "/System/Library"]
userDomainMask
枚举下的结果是一个元素的数组
["/Users/kehaoran/Library/Developer/CoreSimulator/Devices/62FD8F53-9E45-4714-A7A1-890E85E184CE/data/Containers/Data/Application/82A37C04-462E-4C33-9315-C71CC9434F39/Library"]
.preferencePanesDirectory
可以直接获取到Preferences
目录
.cachesDirectory
可以直接获取到Caches
3.temp 目录
let tempPath = NSTemporaryDirectory()