从文件 Swift(适用于 MacOS)将文档加载到 PDFView 中

问题描述 投票:0回答:0

我正在使用带有故事板应用程序的 PDFView。我想从路径“~/Library/Containers/Someone.App/Data/test.pdf”加载一个pdf文档。 我尝试通过以下方式加载 PDFDocument:

@IBOutlet weak var PDFViewer: PDFView!
...    
let url : NSURL! = NSURL(string: "file:///Users/vladimir/Library/Containers/Someone.App/Data/test.pdf")
    PDFViewer.document = PDFDocument(url: url as URL) // This line gives the error

但是我收到“线程 1:致命错误:在隐式展开可选值时意外发现 nil”错误。

有没有办法使用 PDFView 查看本地 pdf 而不会导致此错误?

swift macos storyboard pdfkit
© www.soinside.com 2019 - 2024. All rights reserved.