It's not neccesary/recommended to use external frameworks just for loading an image from an URL.
If you use an external framework you are adding unnecesary codes to your project because there is no framework that just add a function to load an image, it's probably that you are adding more unnecesary stuff with that framework.
I recommend you to implement it by yourself! It going to be more performant and easy than adding an external framework.
This is a code to load an image without external frameworks:
import UIKit
typealias GMImageServiceSuccess = (UIImage) -> Void
typealias GMImageServiceFail = (Error) -> Void
class GMImageService {
// MARK: - Class vars.
private static let imageServiceCache = NSCache<NSString, UIImage>()
// MARK: - Vars.
private var currentDataTask: URLSessionDataTask?
// MARK: - Fetch images functions.
func gmImageFromURL(_ urlString: String, sucess: GMImageServiceSuccess?, fail: GMImageServiceFail?) {
if let imageFromCache = GMImageService.imageServiceCache.object(forKey: urlString as NSString) {
sucess?(imageFromCache)
return
}
guard let imageURL = URL(string: urlString) else {
// ERROR.
return
}
URLSession.shared.dataTask(with: imageURL) { data, response, error in
guard let imageData = data else {
// ERROR.
return
}
if let imageToCache = UIImage(data: imageData) {
DispatchQueue.main.async {
GMImageService.imageServiceCache.setObject(imageToCache, forKey: urlString as NSString)
sucess?(imageToCache)
}
} else {
// ERROR.
}
}.resume()
}
// MARK: - Cancel images functions.
func mpImageCancelCurrent() {
if let currentTask = self.currentDataTask {
currentTask.cancel()
}
}
}
Let me know if you need to implement an image cache, it's easy in swift!