This is how I set images to UIImageView from a web url:
import UIKit
extension UIImageView {
private var storage: Storageable {
Assembler.shared.resolve(Storageable.self)!
}
private var imageDownloader: ImageDownloaderable {
Assembler.shared.resolve(ImageDownloaderable.self)!
}
// MARK: - Internal
func setImage(with url: URL) {
downloadImage(with: url) { [weak self] image in
self?.image = image
}
}
func downloadImage(with url: URL, completion: @escaping ImageHandler) {
imageDownloader.setAuthorization(withToken: storage.bearerToken)
sd_setImage(with: url, placeholderImage: nil,
options: [.allowInvalidSSLCertificates, .avoidAutoSetImage]) { image, _, _, _ in
completion(image)
}
}
}
How do I tell SDWebImage library to downsample an image to specific size, to reduce memory usage. Is it possible?