Properties2
| Type | Concept |
| Note created | Feb 17, 2025 |
A SwiftUI view is a struct that inherits the View Protocol. They are used to define (in a declarative way) how the information should be presented on screen.
Views are structs
Even though we could expect them to be classes (as they were in UIKit), they are structs mostly because of their speed and simplicity.
If you inherit a class, they can have plenty of values and methods stored that you may not be expecting. If your struct holds an integer, there is only that single integer in it, and is therefore almost free to create.
However, it also forces the developer to think about state isolation: classes can be modified at any point, but structs cannot. That’s why it’s possible for SwiftUI to refresh views each time a stateful property is modified.