Views
Basic building blocks of user interfaces.
Define a piece of UI
Prefer smaller, single-purpose view
The entire SwiftUI framework is oriented around composition of small pieces: organize the code in the same way
Each view is a
Struct,therefore not inheriting anythingEach view defines a small piece of UI, it doesn’t have to take care of everything
Views are not persistent objects that we update over time using imperative event-based code.
Views are defined declaratively as a function of their inputs.
Container Views
Container views are declared as a composition of other views serving as their content.
Those Content views are declared within a special kind of closure known as a @ViewBuilder.
For example, use the Form container to make things look like a normal settings screen
$bindings
We use the leading dollar sign prefix to indicate that we should pass a binding in our state instead of just passing a read-only value.
A binding is a kind of managed reference that allows one view to edit the state of another view.
Primitive Views
Controls
Describe purpose, not visuals
Adaptive and reusable
Customizable
Accessible out of the box
@environment property
Connected to the environment value.
We can use its value just like any other property.
The environment is a great encapsulation for pushing data down through the view hierarchy.
