0

So I want to view pdf from core data but stuck on this issue

struct PDFView: View {
    var pdfData: Data?

    var body: some View {
        if let pdfData = pdfData, let document = PDFDocument(data: pdfData) {
            PDFKitView(document: document)
        } else {
            Text("PDF Not Found")
        }
    }
}

struct PDFKitView: UIViewRepresentable { // Type 'PDFKitView' does not conform to protocol 'UIViewRepresentable'
    let document: PDFDocument

    func makeUIView(context: Context) -> PDFView {
        PDFView()
    }

    func updateUIView(_ uiView: PDFView, context: Context) {
        uiView.document = document // Value of type 'PDFView' has no member 'document'
    }
}

I have google it and look on similar question but it doesn't help me.

any suggestion on how to make the PDFKitView conform to protocol 'UIViewRepresentable' and dix "Value of type 'PDFView' has no member 'document'"?

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
  • I think you're confusing things by naming your SwiftUI `View` `PDFView`, which is already something used by the system in PDFKit: https://developer.apple.com/documentation/pdfkit/pdfview. Rename _your_ view and then the `PDFView()` inside your `PDFKitView` will refer to the correct (Apple) version – jnpdx Jul 06 '23 at 21:36
  • Does this answer your question? [SwiftUI: Type does not conform to protocol 'UIViewRepresentable' // My Code](https://stackoverflow.com/questions/75176496/swiftui-type-does-not-conform-to-protocol-uiviewrepresentable-my-code) – lorem ipsum Jul 06 '23 at 23:38

0 Answers0