[英]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.