Daily iOS
SwiftUI

List item identity

In a SwiftUI List showing live prices, every price update makes rows flicker and reappear and the scroll position jumps. How should you define the model's Identifiable id?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Make the id a domain key that doesn't change when the price does, like a ticker symbol or market code (for example BTC-KRW), and keep the price, update time, and a UUID() created on every decode out of it, so List sees a value change on the same row and updates it in place.

Share a question