Caching Online Images Using AlamofireImage
. It works on top of Alamofire
in Swift.
Install AlamofireImage
using cocoapods
pod 'AlamofireImage', '~> 3.1'
SetUp:
AlamofireImage
and Alamofire
let imageCache = AutoPurgingImageCache( memoryCapacity: 111_111_111, preferredMemoryUsageAfterPurge: 90_000_000)
Alamofire.request(self.nameUrl[i]).responseImage { response in
if response.result.value != nil {
let image = UIImage(data: response.data!, scale: 1.0)!
imageCache.add(image, withIdentifier: self.nameUrl[i])
}
}
if let image = imageCache.image(withIdentifier: self.nameUrl[self.a])
{
self.localImageView.image = image
}
For more Info follow this link