I'm using Kingfisher framework to prefetch images. The link to the Kingfisher framework is: https://github.com/onevcat/Kingfisher
Here's my code that I've written:
func downloadImages() {
if(self.albumImagePathArray.isEmpty == false) {
//dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
let urls = self.albumImagePathArray.map { NSURL(string: $0)! }
let prefetcher = ImagePrefetcher(urls: urls, optionsInfo: nil, progressBlock: nil, completionHandler: {
(skippedResources, failedResources, completedResources) -> () in
print("These resources are prefetched: \(completedResources)")
})
prefetcher.start()
}
}
I'm not sure how to use this framework as I'm quite new to App development. Once I have prefetched the images, how do I get these prefetched images from cache. I want to pick these images from cache and put them into an array of UIImage. Previously I was not picking from cache, but I was loading the URLs every time and putting them an array of strings called albumImagePathArray and through contentsOfURL I was converting it into UIImage so it can be put into albumImages as shown in the code below:
var albumImages = [UIImage]()
for i in 0 ..< self.albumImagePathArray.count
{
let image = UIImage(data: NSData(contentsOfURL: NSURL(string: self.albumImagePathArray[i])!)!)
self.albumImages.append(image!)
}
Now I want to change all that, I want to pick directly from cache after prefetching so I don't have to download the images every time which takes lot of time. Can anyone please help me on this? Thanks a lot!
I'm also new at iOS Dev and I'm using kingfisher for storring images to cache.
To get into the point while you prefetch the images there is an
optionInfo
which you leave itnil
. So if i guess right you prefetch images from URLs, so in thisoptionInfo
you can set a Cache Identifier for each image, and would be best if you put there the URL of the image.Kingfisher documentation is pretty clear about the
optionInfo
so you could change your function to thisSo with this practise you can store them to Cache. To continue you have to show us what you have tried after the prefetch.