Lazily Load Images in Swift
Don’t forget the dependency injection!
2 min readApr 13, 2021
Difficulty: Beginner | Easy | Normal | Challenging
This article has been developed using Xcode 12.4, and Swift 5.3.2
You can access a video version of this article @https://youtu.be/Szjjj4rWMIs
A simple problem that requires an article — now perhaps you want to lazy load images in a UITableView
; but how would you possibly do that?
Even more important — how can we use dependency injection for this?
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
Which calls the following code within an extension on UIImageView
: