How do you debug a UICollectionView cell reuse bug that only appears during fast scrolling?

Turn a vague rendering issue into a disciplined diagnosis around state leakage, async work, and view configuration boundaries

Answer

First diagnosis step

Define the cell's full visual contract. Bugs during fast scrolling usually come from configuration state that leaks across reuse or from asynchronous work finishing after the cell has been reassigned.

Checklist

  1. Reset every transient visual property in prepareForReuse().
  2. Cancel image work or task handles tied to the previous model.
  3. Make configuration idempotent so calling it repeatedly does not compound state.

Example

swift
override func prepareForReuse() {
    super.prepareForReuse()
    imageTask?.cancel()
    imageTask = nil
    thumbnailView.image = nil
    badgeLabel.isHidden = true
}

What a strong answer sounds like

It is methodical. You explain how you would reproduce the bug, narrow the surface area, and separate reuse, async loading, and model identity as distinct causes.