Kingfisher to download images
when we need to download images from URL its difficult task to download image in an efficient way and also store it to cache. For Objective-C, we are using library SDWebImage and for swift, you can use the Kingfisher library to download the images easy and fast as compared to the other libraries. Using Kingfisher you can easily download images. Example of download images:-
1 |
yourImageView.kf.setImage(with: URL(string: "image url")) |
If you want to store image in Kingfisher cache and fetch image follow this
1 2 3 4 5 6 7 8 |
if URL(string: item.pictureUrl!) != nil { let resource = ImageResource(downloadURL: URL(string: "image url"), cacheKey: item.pictureUrl!) yourImageView.kf.setImage(with: resource, placeholder: placeholder image, options: nil, progressBlock: nil, completionHandler: nil) } else{ yourImageView.image = placeholder image } |