Я использую af_setImage() для установки изображения в UIImageView. Мне нужно кэшировать изображение, и если оно кэшировано, я хочу, чтобы оно не переходило. Я пробовал некоторые коды ниже, но кеш изображений с идентификатором всегда возвращает ноль. Кажется, что imageCache.add() вызывается каждый раз, но не добавляет кеш.
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)
}
}
)
}
Что я не так?
Заранее спасибо( ´ ▽ ` )