前提・実現したいこと
プロジェクトに取り込んだPDFのURLを取得し、その後表示させたいのですが
エラーが出てしまいます。
ご教授よろしくお願いいたします。
###エラー
swift
1let pdfURL = URL(fileURLWithPath: path)
Use of unresolved identifier 'path'
該当のソースコード
Swift
1 2 override func viewDidLoad() { 3 super.viewDidLoad() 4 5 let pdfView = PDFView(frame: view.frame) 6 7 let hoge = UserDefaults.standard.integer(forKey: "selectedTag") 8 9 switch hoge { 10 case 1: 11 print("展開1") 12 13 // 読み込み 14 // PDFDocument 15 let path: String = Bundle.main.path(forResource: "huto1", ofType: "pdf")! 16 print("取得") 17 print(path) 18 19 case 2: 20 print("展開2") 21 let path: String = Bundle.main.path(forResource: "huto2", ofType: "pdf")! 22 print("取得") 23 print(path) 24 25 default:break 26 } 27 28 let pdfURL = URL(fileURLWithPath: path) 29 let document = PDFDocument(url: pdfURL) 30 pdfView.document = document 31 //pdfView.backgroundColor = .lightGray 32 33 // PDFの拡大率を調整する 34 pdfView.autoScales = true 35 // 表示モード 36 pdfView.displayMode = .singlePageContinuous 37 38 view.addSubview(pdfView) 39 40 41 } 42
ファイルのURLはprintされます。
補足情報(FW/ツールのバージョンなど)
Swiftのversionは4.1.2
Xcodeのversionは9.4.1
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/13 13:22