Smoothly Download Images on Tableview and General Purpose

Please read below code and Implement.

To use UIimageView extension for swift

import Foundation

import UIKit

extension UIImageView {

func downloadedFrom(url: URL, contentMode mode: UIViewContentMode = .scaleAspectFit) {

contentMode = mode

URLSession.shared.dataTask(with: url) { (data, response, error) in

guard

let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,

let mimeType = response?.mimeType, mimeType.hasPrefix(“image”),

let data = data, error == nil,

let image = UIImage(data: data)

else { return }

DispatchQueue.main.async() { () -> Void in

self.image = image

}

}.resume()

}

func downloadedFrom(link: String, contentMode mode: UIViewContentMode = .scaleToFill) {

guard let url = URL(string: link) else { return }

downloadedFrom(url: url, contentMode: mode)

}

}

Use it

let iconImageView:UIImageView?iconImageView?.downloadedFrom(link:URL for Image as String format)