简体   繁体   中英

using pdfkit to display pdf

I'm trying to load a pdf that is stored in my app, here is the code that I have

import UIKit
import PDFKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let pdfView = PDFView(frame: UIScreen.main.bounds)
        let url = Bundle.main.url(forResource: "example", withExtension: "pdf")
        pdfView.document = PDFDocument(url: url!)
        self.view.addSubview(pdfView)
    }

When I am running in simulator, I am getting the error that fatal error: unexpectedly found nil while unwrapping an Optional value in the debug are it is showing that url is nil .Any idea how to resolve it? I am running swift 4 and iOS 11 as target

Please click the checkbox under Target Membership in File Inspector.

文件检查员 - 目标会员

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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