为什么 FileManager 和 Finder 不匹配?

Why is there a mismatch between FileManager and Finder?

如果我在模拟器启动时打印文档目录,我会得到:

let simulatorPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
print(simulatorPath)


//prints -> /Users/name/Library/Developer/CoreSimulator/Devices/[device-id]/data/Containers/Data/Application/[application-id]/Documents

如果我用 Finder 打开这个目录,那里还有一些其他文件夹:/Library、/SystemData 和 /tmp。具体来说,/Library/Caches/[domain.app]/[几个缓存文件].

但是,在我的应用程序中,我正在使用文件管理器创建一个 sqlite 数据库。如果我在创建数据库后执行以下操作:

var path = FileManager.default.currentDirectoryPath + "Library/Caches"

let enumerator = FileManager.default.enumerator(atPath: path)
while let obj = enumerator?.nextObject() as? String {
  print(obj)
}

这是打印出来的:

ColorSync
ColorSync/com.apple.colorsync.devices
Desktop Pictures
Desktop Pictures/78DJQ81B-3D2C-46C7-A268-3CE1903213FE
Desktop Pictures/78DJQ81B-3D2C-46C7-A268-3CE1903213FE/lockscreen.png
domain.app
domain.app/SQLite
com.apple.cloudkit
com.apple.cloudkit/com.apple.cloudkit.launchservices.hostnames.plist
com.apple.iconservices.store
app
app/SQLite
app/SQLite/cache.db

但是 /Library/Caches/[domain.app] 文件夹的内容在使用枚举器打印时与在 Finder 中访问时不同。我假设

错了吗
NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]

FileManager.default.currentDirectoryPath + "/Documents"

指向同一位置?

在 Finder 中摸索了一段时间后,我发现我正在创建的 SQLite 数据库文件显示在 /Library/Caches 中,但在我硬盘的根目录中。根据 docs 对于 FileManager.default.currentDirectoryPath:

When an app is launched, this property is initially set to the app’s current working directory. If the current working directory is not accessible for any reason, the value of this property is nil.

鉴于此,我想当我打印那个值时,/ 出来了,它是相对于模拟应用程序的当前目录。如果有人知道为什么会这样,欢迎评论。