title: How to properly return an image from QLThumbnailGenerator? (SwiftUI)
body: <p><strong>My Problem</strong>
  How do I return a cgImage from QLThumbnailGenerator.shared.generateRepresentations(for: ... )?</p>
  
  <p><strong>My Hangups/Attempt (Code Below)</strong>
  My attempt has a function (line 13) that returns a CGImage for a ListView entry (line 39). I tried to use an empty CGImage (line 18), but its init parameters are confusing and seem excessive for a simple thumbnail. I'm likely going about this incorrectly.</p>
  
  <p><strong>Notes</strong>
  CGImage is used so the same code can work for both iOS and MacOS Catalyst. (Saw this in WWDC 2019 session 719.)
  I tried but failed to glean an answer from:
   - <a href="https://developer.apple.com/documentation/quicklookthumbnailing/creating_quick_look_thumbnails_to_preview_files_in_your_app" rel="nofollow noreferrer">https://developer.apple.com/documentation/quicklookthumbnailing/creating_quick_look_thumbnails_to_preview_files_in_your_app</a>
   - <a href="https://forums.developer.apple.com/message/375807" rel="nofollow noreferrer">https://forums.developer.apple.com/message/375807</a></p>
  
  <p><strong>Apology/Gratitude</strong>
  Thanks for your patience, as the answer is likely obvious and my vocabulary likely off. My dumb brain tunes out lectures without a little hands-on experience, so I started this first app from zero programming knowledge as a quarantine hobby. I'll return to the theory lectures after.</p>
  
  <p><strong>ResultsView.swift</strong></p>
  
  <pre><code>
  
  import SwiftUI
  import MobileCoreServices
  import Combine
  import QuickLookThumbnailing
  import CoreImage
  import UIKit
  
  struct ResultsView: View {
      @EnvironmentObject var parsedScreeningData: ParsedScreeningData
      @EnvironmentObject var search: Search
  
      func generateThumbnail(ofThis: String) -&gt; CGImage {
          let url = self.search.libraryFolder.appendingPathComponent(ofThis)
          let size: CGSize = CGSize(width: 68, height: 88)
          let request = QLThumbnailGenerator.Request(fileAt: url, size: size, scale: (UIScreen.main.scale), representationTypes: .all)
          let generator = QLThumbnailGenerator.shared
  
          var image = CGImage()
  
          generator.generateRepresentations(for: request) { (thumbnail, type, error) in
              DispatchQueue.main.async {
                  if thumbnail == nil || error != nil {
                      assert(false, "Thumbnail failed to generate")
                  } else {
                      image = thumbnail!.cgImage
                  }
              }
          }
          return image
      }
  
  
  
  var body: some View {
      VStack{
  
          List(search.searchResults) { datum in
              HStack {
                  Image(self.generateThumbnail(ofThis: datum.PDFname), scale: (UIScreen.main.scale), label: Text("PDF"))
                  Text("File: \(datum.PDFname)")
                  Text("Cell line: \(self.parsedScreeningData.parsedScreeningData[datum.termFoundIndex].misidentifiedCellLine)")
                      .padding(.trailing, 10)
                      .padding(.leading, 10)
                  Spacer()
                  Image(systemName: "eyeglasses").foregroundColor(ColorManager.iconGreen)
                  } // HStack
              } // List
          }// Vstack
          .colorMultiply(ColorManager.beigeMedium)
              .padding(.trailing, 0)
              .padding(.leading, 0)
              .listStyle(GroupedListStyle())
  
      } // body
  } // ResultsView struct
  
  
  struct ResultsView_Previews: PreviewProvider {
      static var previews: some View {
          ResultsView().environmentObject(ParsedScreeningData()).environmentObject(Search())
      }
  }
  
  </code></pre>