如何在我的自定义目录中创建文件夹并提前在 /myapp/documents 中创建一个文件夹(当我构建应用程序时)?

How can I make folders in my custom directory and create create a folder in /myapp/documents in advance(when I build the app)?

我正在为 iOS 和 ipadOS 制作一个词汇应用程序。结构是

文件夹(雅思、TOPFL 等)-> 词汇(剑桥雅思、牛津雅思等)-> 单词(玩耍、睡觉等)

词汇文件将是 .txt 文件,所以我可以把它改成这样

["word1" : "meaning1"], ["word1", "meaning2"], ....

而且我想在用户安装应用程序时制作文件夹文件。

所以这将是我的 app/documents/folders

但是当我安装应用程序时,它变成了我的 app/documents/,没有文件夹。

iOS 上是否有安装脚本之类的东西?

第二个问题是我创建文件夹的时间

let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
let documentsDirectory = paths[0]
let docURL = URL(string: documentsDirectory)!
let dataPath = docURL.appendingPathComponent(String(AddNewFolder.text!)) // AddNewFolder is a Text Field
if !FileManager.default.fileExists(atPath: dataPath.absoluteString) {
    do {
        try FileManager.default.createDirectory(atPath: dataPath.absoluteString, withIntermediateDirectories: true, attributes: nil)
    } catch {
        print(error.localizedDescription);
    }
}

如何在 myapp/documents/folders 而不是 /myapp/documents 中创建新文件夹?

第三个问题是关于 UIKit 与 SwiftUI 的对比。什么更快,什么更容易使用?

而在SwiftUI中,有SwiftUI App和UIKit delegate,什么是UIKit delegate?(这是否意味着我在SwiftUI中使用了UIKit?)

我用谷歌搜索了整整一个星期。答案是

// make subdirectory "vocabFolder" if it doesn't exist
let VocabFolderPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("vocabFolder")

if !FileManager.default.fileExists(atPath: VocabFolderPath.absoluteString) {
    try! FileManager.default.createDirectory(at: VocabFolderPath, withIntermediateDirectories: true, attributes: nil)
}
    
// create custom vocab folder
let CustomVocabFolderPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("vocabFolder/\(String(AddNewFolder.text!))")
    
if !FileManager.default.fileExists(atPath: CustomVocabFolderPath.absoluteString) {
    try! FileManager.default.createDirectory(at: CustomVocabFolderPath, withIntermediateDirectories: true, attributes: nil)
}

并导航 Simualtor 设备,执行 open 'xcrun simctl get_app_container booted BUNDLE_IDENTIFIER data' -a Finder