1

I'm trying to pre-load some images with the following code:

let thumbnailUrl = NSURL(string: urlString)
let fetcher = NetworkFetcher<UIImage>(URL: thumbnailUrl)
Shared.imageCache.fetch(fetcher) {
    println("Finished")
}

But afterwards when I try to set it to the imageview, it downloads it again from the network instead of reading it from the cache. This is the code:

self.imageView.hnk_setImageFromURL(
    NSURL(string: urlString)
    success: { thumbnail in
        println("Finished setting image")
    }
)

Is this a bug or maybe I missunderstood the usage of imageCache.fetch()?

PD: I put breakpoints in the whole code, and I can guarantee the key for the cache (in this case, the url) is exactly the same, so I have no clue why the cache isn't resolving when used with .hnk_setImageFromURL()

Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

1 Answers1

3

I was stuck on this for 3 days. I hope this answer might help someone else in the future.

The issue was that I didn't specify a Format Name to the fetcher, while the UIImageView.hnk_setImageFromURL() does. The way to fix it is:

let thumbnailUrl = NSURL(string: urlString)
let fetcher = NetworkFetcher<UIImage>(URL: thumbnailUrl)
let cache = Shared.imageCache
let format = self.imageView.hnk_format

cache.fetch(fetcher, formatName: format.name) {
    println("Finished")
}
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206