Migrating to Observable
Before migrating to Observable, we must ensure that our app deployment target is at least 17. Remember that this feature (and most of the new features described in this book) are from iOS 17, and some are irrelevant if our app deployment target is not 17.
Let’s try to recap the different Observable attributes:
@State
: This is used to manage the state within a specific view. A change to a@State
property triggers a view update. For example, data related to a list or view visibility can be marked as@State
.@Observable
: This can be applied to a class to make the class observable. Each class property is automatically marked with@Published
unless we mark them as@ObservataionIgnored
.@Observable
can be added to view models or business logic classes.@Bindable
: This creates a two-way connection between a property and another value. Text field input, toggles, or a counter are examples of views for implementing a@
Bindable
connection.
...