Patonz Patonz - 1 year ago 216
iOS Question

Get UIImage only with Kingfisher library

I need to get a UIImage only instead of loading a normal UIImageView with Kingfisher library

To realize it I implemented a workaround with UIImageView:

let imageView = UIImageView()

imageView.kf_setImageWithURL(NSURL(string: cpa.imageName)!, placeholderImage: nil,
optionsInfo: [.Transition(ImageTransition.Fade(1))],
progressBlock: { receivedSize, totalSize in
completionHandler: { image, error, cacheType, imageURL in
anView!.image = image //anView IS NOT an UIImageView
anView!.frame.size = CGSize(width: 15.0, height: 15.0)

This code works perfectly, but I would like to do it in a cleaner way.
Is there a method in this library to get an UIImage only? Async and cached

Answer Source

You could use the retrieveImageWithURL(:optionsInfo:progressBlock: completionHandler:) method of KingfisherManager for this.

Maybe something like this:

KingfisherManager.sharedManager.retrieveImageWithURL(url, optionsInfo: nil, progressBlock: nil, completionHandler: { (image, error, cacheType, imageURL) -> () in
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download