Patonz Patonz - 9 days ago 6
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
print("\(receivedSize)/\(totalSize)")
},
completionHandler: { image, error, cacheType, imageURL in
anView!.image = image //anView IS NOT an UIImageView
anView!.frame.size = CGSize(width: 15.0, height: 15.0)
print("Finished")
})


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

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
    print(image)
})
Comments