How to use .quickLookPreview modifier in swiftui
Asked Answered
F

1

6

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

Furtek answered 13/12, 2021 at 22:1 Comment(18)
Can you share your code with us?Salomie
@Salomie Updated the question with codeFurtek
This needs a Minimal, Reproducible Example.Osber
@Osber what else is missing? This is the most basic version of the code that runs well on iOS but throws the error on mac.Furtek
How are you obtaining your URL path? Is it an app file? What kind of file is it?Osber
@Osber 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 fileFurtek
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?Osber
@Osber Okay, I will update to Xcode 13.2 and run it again. ThanksFurtek
And make a new test app.Osber
@Osber why does it still throw error on an old project even though it runs on Xcode version 13.2?Furtek
Let us continue this discussion in chat.Osber
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.Ursas
@Ursas 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.Furtek
Heyman, please checkout my question and answer at #71487949 . It worked on my Mac for me.Ursas
@Ursas Yeah run the same code now in Xcode 13.2 and I see the issue is fixed and it works.Furtek
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."Reminiscence
It appears support for this has been completely removed for Catalyst? No mention of Catalyst at developer.apple.com/documentation/swiftui/view/… and I'm unable to build for Catalyst with the .quickLookPreview modifier.Wilburnwilburt
@LeoKlaus no it is not supported on catalystFurtek
F
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.

Furtek answered 23/3, 2022 at 10:51 Comment(1)
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."Reminiscence

© 2022 - 2024 — McMap. All rights reserved.