I am using af_setImage() to set an image to a UIImageView. I need to cache image and if it's cached, I want it not to make transition. I have tried some codes below but the image cache with identifier always returns nil. It seems that imageCache.add() is called every time but it doesn't add the cache.
let imageCache = AutoPurgingImageCache()
if let image = imageCache.image(withIdentifier: post.mainImage) {
cell.postImageView.image = image
} else {
cell.postImageView.af_setImage(
withURL: URL(string: post.mainImage)!,
placeholderImage: PostCellView.defaultImage,
imageTransition: .crossDissolve(0.5),
completion: { response in
if let image = response.result.value, response.result.isSuccess {
imageCache.add(image, withIdentifier: post.mainImage)
}
}
)
}
What am I wrong?
Thank you in advance( ´ ▽ ` )