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!