Properties2
TypeConcept
Note createdFeb 17, 2025

When using SwiftUI, we may need to provide some simple state to modify View structs (for example, a counter). This is not possible since those are created constant and their properties (where we would store the state) are immutable.

However, we can overcome this issue by adding the @State property wrapper, that will magically fix it for us. This is generally advised against, and you should not rely often on it. Also, it is considered a good practice to make all these properties private (@State private var name).

The @State wrapper will automatically watch for changes, and reload the body property once they happen.