- State management in Swift happens by just declaring variables instead of constants (e.g.,
var welcomeText: String = "Hello, user!"), but, SwiftUI doesn't like this because it doesn't know that the variable will at some point change, and since we are working with UI elements, the View protocol should update according to the value of the variable. That's where the state property wrapper comes into play. State can be applied to any variable inside of a Swift Application, but as a general rule, you should try to only use it with simple struct types such as String, Int, arrays, and generally shouldn't be shared with other views. Sharing State can be done using@ObserverObjector@EnvironmentObjectinstead, which we will get into later. (e.g.,@State var welcomeText: String = "Hello, user!")