23. SwiftUI Observable and Environment Objects – A Tutorial
The chapter entitled Working with SwiftUI State, Observable and Environment Objects introduced the concept of observable and environment objects and explained how these are used to implement a data driven approach to app development in SwiftUI.
This chapter will build on the knowledge from the earlier chapter by creating a simple example project that makes use of both observable and environment objects.
23.1 About the ObservableDemo Project
Observable objects are particularly powerful when used to wrap dynamic data (in other words, data values that change repeatedly). To simulate data of this type, an observable data object will be created which makes use of the Foundation framework Timer object configured to update a counter once every second. This counter will be published so that it can be observed by views within the app project.
Initially, the data will be treated as an observable object and passed from one view to...