iOS 17 changes in state management
State management is related to architecture in SwiftUI applications as, in a SwiftUI application, you need to bind state changes to the UI, as SwiftUI is declarative and does not have “methods” that you can call to determine changes in the UI. These changes need to be achieved by declaration and state binding. SwiftUI will automatically redraw the views affected by the changes in the underlying data.
With iOS 17 and Xcode 15, presented during the WWDC2023 conference, Apple introduced some variations to all the binding mechanisms we have just examined: @Observable
is used rather than ObservableObject
, while we are expected to use @Bindable
to mark individual properties we would want to be able to bind. @Bindable
usage is limited to classes marked as @Observable
. If you deliberately want to avoid observing a property, you can use ObservationIgnored
to mark that specific property.
The @Observable
property wrapper is the easiest way...