I have an NSCollectionView which is showing thumbnails of images and I have just switched to using QLThumbnailGenerator to fetch them.
There are over 6,000 possible images that can be viewed and, if I scroll too fast, I start to get the wrong thumbnails returned from the generator.
Is this a bug, or is there something I can do to fix this?
Here is the code that is written inside the NSCollectionViewItem derived class…
var request: QLThumbnailGenerator.Request?
func loadImage()
{
if imageView?.image != NSImage(imageLiteralResourceName: "Placeholder")
{
return
}
request = QLThumbnailGenerator.Request(fileAt: url!, size: imageSize, scale: 1.0, representationTypes: [.lowQualityThumbnail])
QLThumbnailGenerator.shared.generateBestRepresentation(for: request!)
{
(thumbnail: QLThumbnailRepresentation?, error: Error?) -> Void in
if let request = self.request
{
QLThumbnailGenerator.shared.cancel(request)
}
DispatchQueue.main.async
{
[unowned self] in
if self.imageView?.image != NSImage(imageLiteralResourceName: "Placeholder")
{
return
}
let transition = CATransition()
transition.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)
transition.duration = 0.3
imageView?.layer?.add(transition, forKey: nil)
imageView?.image = thumbnail?.nsImage
…