Last active
October 15, 2019 15:47
-
-
Save rsaenzi/99cebf84857eb95069630d43da68167f to your computer and use it in GitHub Desktop.
Function lo load async an image using Kingfisher pod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // UIImageView+Async.swift | |
| // | |
| // Created by Rigoberto Sáenz Imbacuán (https://www.linkedin.com/in/rsaenzi/) | |
| // Copyright © 2019. All rights reserved. | |
| // | |
| import UIKit | |
| import Kingfisher | |
| extension UIImageView { | |
| func loadAsync(_ imageUrl: String) { | |
| guard let downloadURL = URL(string: imageUrl) else { | |
| self.image = nil | |
| return | |
| } | |
| let placeholder = UIImage(named: "PlaceholderBanner") | |
| let options: [KingfisherOptionsInfoItem] = [.transition(.fade(0.5)), .cacheOriginalImage] | |
| let resource = ImageResource(downloadURL: downloadURL, cacheKey: imageUrl) | |
| self.kf.setImage( | |
| with: resource, | |
| placeholder: placeholder, | |
| options: options, | |
| progressBlock: nil, | |
| completionHandler: { _ in }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment