Going over the SwiftUI observation system
Before we discuss the current SwiftUI observation system, let’s recap the SwiftUI observation system.
Before Xcode 15, nine property wrappers handled state and data updates in SwiftUI.
Let’s try to group them by app levels:
- Sub-View level:
@
Binding
,@Environment
- View level:
@State
,@Binding
,@
StateObject
,@Environment
- Business Logic level:
@
ObservableObject
,@Published
- App/Data level:
@AppStorage
,@
SceneStorage
,@EnvironementObject
The different levels give us an idea of the different roles of the different wrappers. Let’s touch on some of these wrappers to understand how the system works.
A local @State
property wrapper manages the state of primitive properties within the view. For example, whether a specific view is hidden, the number of available buttons, the current sorting method, and more are managed by this wrapper.
The reason why we use a @State
property wrapper is because...