Lazily Load Images in Swift

Don’t forget the dependency injection!

https://youtu.be/Szjjj4rWMIs

Prerequisites

You will be expected to be aware how to make a Single View Application in Swift.

The standard answer

You can use an extension for this, so we can call it straight after setting the image placeholder

The alternative answer

This can be done — and without changing the way that we can call the lazy loading of images too!

The full implementation

I’ve written this code in my VIPER example, and please do take a look as this is a really nice article to read and learn from, and of course has this code in situ for you and ready to go!

Conclusion

This is important stuff! You would want to lazily load images in a great deal of situations for creating Apps that are production ready. Before letting your users loose on your application you would like a great user experience. That is, you would really need to use lazy loading for your images.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store