ios_catalogue1-4 Exercise 3: Why @State Holds the Model ======================================================== With `private let model = ListViewModel()`: A SwiftUI view is a struct, and SwiftUI creates new copies of it whenever it needs to redraw (for example every time items changes). A `let` property is initialised again with each copy, so each redraw would make a BRAND NEW ListViewModel with selectedTypeName = nil. Tapping a chip would set the property on the model, the view would redraw, a new model would be created, and the selection would be lost immediately: the chips would appear not to work. @State tells SwiftUI to keep ONE instance alive for as long as the view stays in the hierarchy, and to hand the same instance to each new copy of the struct. That is why the selection persists across redraws. Rotation: rotating the phone relayouts the view but the view keeps its identity in the hierarchy, so its @State (and therefore the model and the selection) survives. (This is easier than Android, where rotation destroys the activity and a ViewModel was needed to keep state.) Quit and reopen the app: the selection does NOT survive. @State lives in memory, and the app process is gone. To keep a small value like this across launches use @AppStorage (stored in UserDefaults) for a simple value such as the selected type's name, or @SceneStorage to restore it per window/scene. Whether the filter SHOULD persist is a product decision: many people prefer the app to open on "All".