DevPrep

All topics › Real interview tasks

A reused cell shows someone else's image

Middle PRO

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

Practice this before your interview

DevPrep turns these answers into one-minute challenges: what does this code print, find the bug, mock interviews. One challenge a day.

Get DevPrep on the App Store