Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Building a Client App From Scratch - Image download extension
import UIKit
import Alamofire
class ImageManager {
private let session = Alamofire.Session()
static let shared = ImageManager()
func load(url: URLConvertible, completionHandler: @escaping (UIImage) -> Void) -> Void {
session.request(url).responseData(
queue: DispatchQueue.global(),
completionHandler: { response in
if let data = response.data, let image = UIImage(data: data) {
DispatchQueue.main.async {
completionHandler(image)
}
}
})
}
}
import UIKit
import Alamofire
extension UIImageView {
func load(url: URLConvertible) {
backgroundColor = .lightGray
image = nil
ImageManager.shared.load(url: url) { [weak self] image in
self?.backgroundColor = nil
self?.image = image
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.