Kwnstantinos Natsios Kwnstantinos Natsios - 2 months ago 21x
Swift Question

Swift 2 Parse and KingFisher cache images

I'm using KingFisher

library so i can cache the images and if there is anyone familiar with it i want some hints.
So i have the following code

let myCache = ImageCache(name: recipesClass.objectId!)
let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
let optionInfo: KingfisherOptionsInfo = [
if let imageFile = recipesClass[RECIPES_COVER] as? PFFile {

let URL = NSURL(string: imageFile.url!)!

cell.coverImage.kf_setImageWithURL(URL, placeholderImage: nil,
optionsInfo: optionInfo,
progressBlock: { receivedSize, totalSize in
print("\(indexPath.row + 1): \(receivedSize)/\(totalSize)")
completionHandler: { image, error, cacheType, imageURL in
print("\(indexPath.row + 1): Finished")

} else {
cell.coverImage.image = UIImage(named:"logo")

When i first enter the View it loads normally the images with this good anymation. But i also have a refresh button which makes a query to Parse and it checks if there is any new Recipe and then it reloads the data from the collection view and it prints "Finished"

Does this means that it downloads the images again? Or it loads them from Cache??

I'm asking because it appends the images in a different way inside the cells rather than the first time that it loads.

Any idea?

P.S. what i want to do is that in each cell i want to cache the image with the object ID of each recipe so when the cell loads and it has the image cached with this unique object id, to load it from cache and not to download it.


try this code:

var imageView:UIImageView!    
let mCa = ImageCache(name: "my_cache")
    let imagePath = getImagePath("image url")
    imageView.kf_setImageWithURL(NSURL(string: imagePath)!,placeholderImage: UIImage(named: "DefaultImageName"),optionsInfo: [.TargetCache(mCa)])