简体   繁体   English

如何在Swift中的macOS项目中获取当前打开文档的文件路径?

[英]How to get file paths for current open documents in a macOS project in Swift?

I have a macOS project in Swift where I would like to get file paths for current open documents. 我在Swift中有一个macOS项目,我想在其中获取当前打开文档的文件路径。 How can this be achieved? 如何做到这一点?

EDIT: I mean the open documents of the app itself. 编辑:我的意思是应用程序本身的打开文件。 Typically represented as windows or tabs. 通常表示为窗口或选项卡。

PS I check these questions but don't help: How to get file path? PS我检查了这些问题,但无济于事: 如何获取文件路径? Loading documents in Document based app Cocoa question: How to get file path for current open document for the front most application 在基于文档的应用程序 Cocoa中 加载文档 :问题:如何为最前面的应用程序获取当前打开文档的文件路径

You can get the documents from NSDocumentController and the URL from each document. 您可以从NSDocumentController获取文档,并从每个文档获取URL。

for document in NSDocumentController.shared().documents {
    print("\(document.fileURL)")
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM