首页 > 解决方案 > 如何获取我的 iOS 应用程序的根目录?

问题描述

我能够访问我的 iOS 应用程序的当前用户的临时目录,并且我能够访问捆绑路径,如以下代码所示:

    print(FileManager.default.temporaryDirectory)

    print(Bundle.main.bundlePath)

如何访问当前用户的应用程序根目录?我需要根据此链接中文档中的说明创建缓存目录或 Documents 目录:

https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html#//apple_ref/doc/uid/TP40010672-CH2-SW13

Xcode 的 beta 版本提供了一个可以访问主目录的属性,但最新版本的 Xcode 没有。

标签: iosswiftnsfilemanager

解决方案


let fileManager = FileManager.default

let pathOfDir = fileManager.currentDirectoryPath
print(pathOfDir)

这用于获取您的根目录


推荐阅读