When I run my code with breakpoint, I see the thumbnail image, but I cannot see the image in the application. Why ?
Using:
generateThumbnailRepresentations(url: currentFile.localPath)
.resizable()
.scaledToFit()
.frame(width: 60, height: 100)
.aspectRatio(contentMode: .fill)
QLThumbnailGenerator:
func generateThumbnailRepresentations(url: String) -> Image {
let pathURL = URL(fileURLWithPath: url)
var image: UIImage = UIImage()
// Set up the parameters of the request.
let size: CGSize = CGSize(width: 60, height: 100)
let scale = UIScreen.main.scale
// Create the thumbnail request.
let request = QLThumbnailGenerator.Request(fileAt: pathURL,
size: size,
scale: 1.0,
representationTypes: .thumbnail)
// Retrieve the singleton instance of the thumbnail generator and generate the thumbnails.
let generator = QLThumbnailGenerator.shared
generator.generateRepresentations(for: request) { (thumbnail, type, error) in
DispatchQueue.main.async {
if thumbnail == nil || error != nil {
// Handle the error case gracefully.
print("error \(error)")
} else {
// Display the thumbnail that you created.
image = thumbnail?.uiImage ?? UIImage(systemName: "photo")!
print("foo")
}
}
}
return Image(uiImage: image)
}