简体   繁体   English

如何在我的自定义目录中创建文件夹并提前在 /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)?

I'm making a vocabulary application for iOS and ipadOS.我正在为 iOS 和 ipadOS 制作词汇应用程序。 The structure is结构是

Folders(IELTS, TOPFL, etc) -> Vocabularies(Cambridge IELTS, Oxford IELTS, etc) -> words(play, sleep, etc)文件夹(雅思、TOPFL 等)-> 词汇(剑桥雅思、牛津雅思等)-> 单词(玩耍、睡眠等)

The Vocabularies file will be .txt file, so I can make it like Vocabularies 文件将是 .txt 文件,所以我可以让它像

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

And I want to make Folders file when users install the app.我想在用户安装应用程序时制作文件夹文件。

So it would be my app/documents/folders所以这将是我的应用程序/文档/文件夹

But when I install the app, it becomes my app/documents/, no folders.但是当我安装应用程序时,它变成了我的应用程序/文档/,没有文件夹。

Is there something like install script on iOS? iOS上有类似安装脚本的东西吗?

And the second question is when I create folder第二个问题是当我创建文件夹时

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);
    }
}

How can I create new folder in myapp/documents/folders, not /myapp/documents?如何在 myapp/documents/folders 而不是 /myapp/documents 中创建新文件夹?

Third question is about UIKit vs SwiftUI.第三个问题是关于 UIKit 与 SwiftUI。 What is faster and what is easier to use?什么更快,什么更容易使用?

And in SwiftUI, there are SwiftUI App and UIKit delegate and what is UIKit delegate?(Does that mean that I use UIKit in SwiftUI?)在 SwiftUI 中,有 SwiftUI App 和 UIKit 委托,什么是 UIKit 委托?(这是否意味着我在 SwiftUI 中使用了 UIKit?)

I googled a whole week.我用谷歌搜索了整整一周。 The answer is答案是

// 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)
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以在 Xcode 中创建一个 Documents 目录,并通过 UI 将我的 iOS 应用程序的文件放入其中吗? 如果是这样,如何? - Can I create a Documents directory in Xcode, and put files in it for my iOS app through the UI. If so, how? 如何在iOS应用程序的默认文档目录中创建文件 - How do i create a file in the default documents directory in an iOS app 如何以编程方式打开带有 myapp 文件夹的默认文件应用程序? - How can i open default Files app with myapp folder programmatically? 在我的 iPhone / 在我的 iPad 文件夹上,如何为我的应用程序创建一个文件夹? - On My iPhone / On My iPad folders, how to create a folder for my app? 在我的 iPhone 文件夹上,如何为我的应用创建文件夹? [iOS 13] - On My iPhone folders, how to create a folder for my app? [iOS 13] 如何在具有自定义扩展名的文档目录中创建文件? - How to create a file in Documents Directory with custom extension? 如何从其他iOS应用程序读取应用程序文档目录中的文档? - How can I read documents in my app's Document directory from other iOS apps? 如何使用我的应用程序文档目录文件夹中的图像创建相册视图? - How to create a photo gallery view with the images which is in my application documents directory folder? 如何使用C#访问iOS App的Documents文件夹 - How can I access Documents folder of iOS App with C# 我可以通过IOS中的phonegap / cordova在www目录中创建文件夹吗? - Can I create a folder in www directory via phonegap/cordova in IOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM