5

I am trying to use the view modifier .quickLookPreview introduced in iOS 14, macOS 11 macCatalyst 14 but I get this error Value of type 'some View' has no member 'quickLookPreview' every time I try to use the modifier on a macOS or mac catalyst target. On iOS, this works fine. What is the right way to present this modifier on a mac?

import SwiftUI
import QuickLook


struct ContentView: View {

@State var documentUrl: URL?

var body: some View {
    NavigationView {

    ZStack {
        
        Button("Press Me", action: {
            documentUrl = URL(fileURLWithPath: "somelocalfileURLPath")
        })
        
        
       
    }
    .navigationTitle("Open File")
    .quickLookPreview($documentUrl)
        
    }
    
}

}

xcode 13.1 MacOS 12.1

Heyman
  • 449
  • 4
  • 13
  • Can you share your code with us? – xTwisteDx Dec 13 '21 at 22:09
  • @xTwisteDx Updated the question with code – Heyman Dec 13 '21 at 22:16
  • This needs a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Yrb Dec 13 '21 at 22:41
  • @Yrb what else is missing? This is the most basic version of the code that runs well on iOS but throws the error on mac. – Heyman Dec 13 '21 at 22:44
  • How are you obtaining your URL path? Is it an app file? What kind of file is it? – Yrb Dec 13 '21 at 23:04
  • @Yrb the URL doesn't really matter in this case. It is just a dummy URL and it still opens as a blank document. I also tested it on a real URL of a local file – Heyman Dec 13 '21 at 23:08
  • The code runs fine then on Xcode 13.2, macOS 11.6.2. Did you make a new app and test the code you posted, before posting? – Yrb Dec 13 '21 at 23:14
  • @Yrb Okay, I will update to Xcode 13.2 and run it again. Thanks – Heyman Dec 13 '21 at 23:17
  • And make a new test app. – Yrb Dec 13 '21 at 23:50
  • @Yrb why does it still throw error on an old project even though it runs on Xcode version 13.2? – Heyman Dec 13 '21 at 23:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/240118/discussion-between-yrb-and-heyman). – Yrb Dec 14 '21 at 01:16
  • Heyman and Yrb, did you manage to solve the problem? If so, could you post the code for getting .quickLookPreview() to work in both iOS and MacOS. – KeithB Mar 16 '22 at 00:13
  • @KeithB No, I never got it to work. I have been asked by an apple developer to file a bug but I don't have the time to do that. – Heyman Mar 21 '22 at 15:51
  • Heyman, please checkout my question and answer at https://stackoverflow.com/questions/71487449/in-my-mac-app-how-can-i-open-a-local-pdf-file-using-a-swiftui-button . It worked on my Mac for me. – KeithB Mar 22 '22 at 15:30
  • 1
    @KeithB Yeah run the same code now in Xcode 13.2 and I see the issue is fixed and it works. – Heyman Mar 23 '22 at 10:49
  • I deleted my previous comment. Sorry, I was wrong, I missed to copy the `QuickLook` import. Now it works. For reference, the deleted comment: "It doesn't work for me on Xcode 13.3, I tried the code example above, and get the same Value of type 'some View' has no member 'quickLookPreview'. I tried it both in a MacOS and an iOS project, with several of the latest versions as deployment targets." – bzyr Apr 10 '22 at 13:57
  • It appears support for this has been completely removed for Catalyst? No mention of Catalyst at https://developer.apple.com/documentation/swiftui/view/quicklookpreview(_:) and I'm unable to build for Catalyst with the .quickLookPreview modifier. – Leo Klaus Mar 04 '23 at 09:42
  • @LeoKlaus no it is not supported on catalyst – Heyman Mar 05 '23 at 13:03

1 Answers1

3

The issue is gone now in Xcode 13.2

So the right way to use the modifier is valid, it was just probably some bug in earlier xcode versions.

Heyman
  • 449
  • 4
  • 13
  • I deleted my previous comment. Sorry, I was wrong, I missed to copy the QuickLook import. Now it works. For reference, the deleted comment: "It doesn't work for me on Xcode 13.3, I tried the code example above, and get the same Value of type 'some View' has no member 'quickLookPreview'. I tried it both in a MacOS and an iOS project, with several of the latest versions as deployment targets." – bzyr Apr 10 '22 at 14:00