A reused cell shows someone else's image
Task
In a list, fast scrolling makes cells flash the wrong images. The cell code:
final class PhotoCell: UITableViewCell {
@IBOutlet private var photoView: UIImageView!
func configure(with url: URL, loader: ImageLoader) {
photoView.image = nil
Task {
let image = try? await loader.image(for: url)
photoView.image = image
}
}
}
Why does it happen and how do you fix it?
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep