The SwiftUI tutorial uses the @State keyword to indicate mutable UI state:
@State var showFavoritesOnly = false
It offers this summ
Its explained nicely with an example in the WWDC video - Session 204 (starts at 16:00, quotation starts at 20:15)
One of the special properties of
@Statevariables is that SwiftUI can observe when they're read and written. Because SwiftUI knows thatzoomedwas read inbody, it knows that the view's rendering depends on it. Which means - when a variable changes the framework is going to ask forbodyagain using the new@Statevalue.
The @State as a Property Wrapper is also elaborated and justified in Data Flow Through Swift UI (5:38) WWDC vid as well. It's shown how it solves the problem when we need a mutable value in an immutable (struct) View.