How to load image from URL in Swift 5

How to load image from URL in Swift 5
April 26, 2020 No Comments Development,iOS Development Pushpendra Kumar

In this tutorial, I have explained to you that how you can load images from URL in UIImageView in iOS with Swift 5. And you will learn this with the help of an extension. And, I would like to tell you that we are not using any third-party library for loading the image. It’s a quite simple and easy way of loading the images. So please follow the complete tutorial and learn deeply about loading the images in iOS from URL. And also follow this for the upcoming tutorials. Because if you wanna be a good developer, you should follow.

load image from URL in UIImageView with Swift 5

You will learn load image from url in swift 5 without using any third party library. So for achieving our goals we will use UIImageView. In actual UIImageView is designed to load only local images, but with a little work you can make it load remote images too.

So for achieving our goal add the below extension in your project.

extension UIImageView {
    func load(urlString : String) {
        guard let url = URL(string: urlString)else {
        } { [weak self] in
            if let data = try? Data(contentsOf: url) {
                if let image = UIImage(data: data) {
                    DispatchQueue.main.async {
                        self?.image = image

😊 Great 😊 After that let use this extension in our project. So now write the below code for loading this images in iOS with swift 5 programming language. 

myImageView.load(urlString: "")

In Conclusion, I hope it is clear that How to load image from URL in Swift 5 programming language. But if still, you have any confusion for the integration then you can visit on my YouTube video. In My Youtube video, I have explained deeply about UIImageView extension and its usage. And also do not forget to subscribe to my YouTube channel. If you are looking more interesting topic then follow the below links and boost your skills.

About The Author
Pushpendra Kumar I am passionate about mobile application development and professional developer at Colour Moon Technologies Pvt Ltd ( This website I have made so that I can meet with new challenges and can share here.

Leave a reply

Your email address will not be published. Required fields are marked *