ฉันกำลังพยายามโหลด pdf
ที่จัดเก็บไว้ในแอปของฉัน นี่คือโค้ดที่ฉันมี
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)
}
เมื่อฉันทำงานในโปรแกรมจำลอง ฉันได้รับข้อผิดพลาดที่ ข้อผิดพลาดร้ายแรง: พบ nil โดยไม่คาดคิดขณะแกะค่าทางเลือก ในการดีบัก แสดงว่า url เป็น nil มีความคิดวิธีการแก้ไขหรือไม่? ฉันใช้ Swift 4 และ iOS 11 เป็นเป้าหมาย