Learning states and observable objects
“States” is a primary topic in SwiftUI and declarative programming. Unlike imperative programming, where we can directly update UI elements on the screen, declarative programming works in the opposite way – we update the state, and the UI is updated according to our changes.
In fact, using states is the only way to create dynamic views in SwiftUI.
SwiftUI uses something called a property wrapper to mark certain variables as states.
Here are some of them:
@State
: To manage simple UI state@Binding
: To allow two directional updates between the view and its children@ObservedObject
: To share data between views@EnvironmentObject
: To share data between views across an app
When asked about SwiftUI, these different property wrappers play a significant role in understanding how SwiftUI works and building a full-featured app with SwiftUI.
If you want to read more about managing user interface...