SwiftUI UIViewRepresentable PDFKit PDFView AttributeGraph: cycle detected through attribute

Viewed 111

Edit: Created a sample project illustrating the issue:

https://github.com/Harold-D/PDFView_Representable

Question:

I'm at a lost, I have this very simple UIViewRepresentable wrapper around PDFView in SwiftUI

import PDFKit
import SwiftUI

struct MyPDFView: UIViewRepresentable {
    typealias UIViewType = PDFView
    @Binding var pdf: Data

    func makeUIView(context _: UIViewRepresentableContext<MyPDFView>) -> UIViewType {
        return PDFView()
    }

    func updateUIView(_ pdfView: UIViewType, context _: UIViewRepresentableContext<MyPDFView>) {
        pdfView.document = PDFDocument(data: pdf)
    }
}

It displays the PDF correctly, but produces about 18 AttributeGraph: cycle detected through attribute messages.

@Binding var pdfStruct: PDFStruct
var body: some View {
    MyPDFView(pdf: Binding($pdfStruct.pdf)!)
}
struct PDFStruct {
    var pdf: Data?
}

How can I eliminate the retain cycle?

0 Answers
Related