Reputation: 665
I am using the code given below to download the image using downloadImageWithURL
method and to assign the image to a UIImageView
and cache the same image using SDImageCache().storeImage
, but i am not able to cache the image. Am i missing anything?
Here is my code:
SDWebImageManager.sharedManager().downloadImageWithURL(profileImageURL,
options: SDWebImageOptions.HighPriority,
progress: { (min:Int, max:Int) -> Void in
})
{ (image:UIImage!, error:NSError!, cacheType:SDImageCacheType, finished:Bool, url:NSURL!) -> Void in
if (image != nil)
{
self.userProfilePic.image = image
SDImageCache.sharedImageCache().storeImage(image, forKey: "userProfilePicImage", toDisk: true)
}
}
Upvotes: 0
Views: 395
Reputation: 11127
SDWebImage
has a Method sd_setImageWithURL
which will download the image and save it to Cache also, you don't need to manually save that image on Cache
Try below code it will solve your problem
self.userProfilePic.sd_setImageWithURL(NSURL(string: "http://www.domain.com/path/to/image.jpg")!, placeholderImage: UIImage(named: "placeholder.png")!)
Upvotes: 0
Reputation: 2241
Looking at the github page, there's a category specifically for UIImageView. Look for Using UIImageView+WebCache category with UITableView
on https://github.com/rs/SDWebImage as they give an example.
This both sets the image, caches it and uses a placeholder image whilst the image is fetching.
Upvotes: 1