无法从包中获取文件URL [英] Not getting file URL from bundle

查看:65
本文介绍了无法从包中获取文件URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在PDFView中加载PDF文件,但无法从Bundle中获取PDF文件URL.

I am loading PDF file in PDFView but unable to get PDF File URL from Bundle.

请检查以下代码:

let pdfView = PDFView(frame: self.view.bounds)
let myFileName = "sample"
guard let url = Bundle.main.url(forResource: myFileName, withExtension: "pdf") else {
         return
}
pdfView.document = PDFDocument(url: url)

self.view.addSubview(pdfView)

每次我在 url 中得到 nil .

这是我的项目窗口:

我犯了任何愚蠢的错误吗?

Am I making any silly mistake ?

请指导我.

预先感谢.

推荐答案

当您在项目中添加任何外部文件并选择bundle target仍未添加时,我不确定它是否位于最新的XCode中,但位于XCode 9.5(Beta)中成捆.

I got problem not sure it's in Latest XCode but in XCode 9.5(Beta) while you adding any external file in your project and select bundle target still its not adding into bundle.

解决方案:

您需要单击要添加到目标捆绑包中的文件,然后从属性窗口中手动检查.

You need to click on file which you want to add into your target bundle and check manually from property window.

请更详细地检查以下屏幕截图:

在将文件添加到项目中时,我已经对其进行了检查,但仍未将其添加到所选目标中.

While adding file into project I have checked it but still its not adding in selected target.

现在我只需要检查相关目标及其预期的工作即可.

Now what I need only check related target and its working as expected.

不确定最新XCode"中的错误或新更新.

Not sure its a bug or new update in Latest XCode.

但是我的问题解决了.

谢谢.

这篇关于无法从包中获取文件URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆