Here is a better solution using thumbnailURL or thumbnailData, since you have a cached images throw whetever alamofire, SDWebImage ...
it's simple and perfect performance wise
For thumbnailURL it accept only local paths:
- get the file path for the cached image
- create a URL object from the file path prefix with "file://"
"file://". to indicate it's local path
if let path = SDImageCache.shared().defaultCachePath(forKey: item.url_thumbnail), let url = URL(string: "file://\(path)") {
attributeSet.thumbnailURL = url
}
For Thumbnail Data
just assign the local url path
attributeSet.thumbnailData = try? Data(contentsOf: url)
to debug and getting know what is going on simply just
do {
attributeSet.thumbnailData = try Data(contentsOf: url)
} catch (let error as NSError) {
print(error)
}