0

I am trying to display a preview of files (like PDF, Pages, Microsoft Docs) in my SwiftUI application for MacOS.

I found Apple's QuickLook framework, which looks perfect for that use. Can I use it in SwiftUI? If I look up the documentation at Apple, I find the QLPreviewController which is a UIViewController.

My approach would, to wrap that UIViewController into a SwiftUI view.. is that the best way? Has anyone tried to do that already?

Summary: how can I display file previews in my SwiftUI MacOS app?

halfer
  • 19,824
  • 17
  • 99
  • 186
davidev
  • 7,694
  • 5
  • 21
  • 56

2 Answers2

0

So, I figured it out finally.

I was able to use the QLPreviewView, which generates a preview view for me. I wrapped it inside a NSViewRepresentable and it worked :)

davidev
  • 7,694
  • 5
  • 21
  • 56
0

This may be what you are looking for

https://danielsaidi.com/blog/2022/06/27/using-quicklook-with-swiftui

import SwiftUI
import QuickLook

struct ContentView: View {

    @State
    var url: URL?

    var body: some View {
        Button("Preview") {
            url = Bundle.main.url(forResource: "meadow", withExtension: "jpg")
        }.quickLookPreview($url)
    }
}
charelf
  • 3,103
  • 4
  • 29
  • 51