如何在一個 macOS 檔案應用程式中處理兩種不同的自定義檔案型別?
從 macOS Document App 模板開始,我定義了兩種型別,它們也在 info.plist 中注冊:
extension UTType {
static var test1: UTType {
UTType(exportedAs: "com.exapmple.test1")
}
}
extension UTType {
static var test2: UTType {
UTType(exportedAs: "com.example.test2")
}
}
蘋果
顯然,對于兩種檔案型別,我需要兩個不同的 New... 選單項。有什么想法可以實作這一目標嗎?
uj5u.com熱心網友回復:
它仍然是NSDocumentController基于的,所以優點和缺點也是相同的 - 我們對默認檔案型別進行自動處理,對于其他所有內容 - 回到編碼。
所以你所做的一切都是正確的,唯一剩下的就是以編程方式添加創建其他(非默認)型別的新檔案。
這是方法的主要部分:
Button("New Document2") {
let dc = NSDocumentController.shared
if let newDocument = try? dc.makeUntitledDocument(ofType: "com.example2.plain-text") {
dc.addDocument(newDocument)
newDocument.makeWindowControllers()
newDocument.showWindows()
}
}
完整的發現和代碼在這里
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/463781.html
上一篇:如何在django模板的if陳述句中使用django變數到javascript字串變數中
下一篇:資料框列中行范圍的總和
