Daily iOS
SwiftUI

Diagnosing @State updates

A junior asks you why the screen doesn't update after they change a @State value in SwiftUI. Start by explaining what @State is.

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

@State is a value type source of truth the view owns. The value is kept in SwiftUI's storage outside the view struct so it survives re-evaluation, and when it changes, any body that read it is evaluated again.

Share a question