This demo application shows how the @EnvironmentStateObject
property wrapper helps an MVVM SwiftUI application access a database. Mainly:
- The main view of the app is kept up-to-date with the information stored in the database.
- A sheet makes sure it gets dismissed as soon as the value it needs no longer exists in the database.
It is also an opportunity to explore a few practices:
- The database is the single source of truth. All views feed from the database, and communicate through the database. This is not a general rule that fits all applications, but it fits well this demo app.
- The application is robust against surprising database changes. Surprises usually happen as your application evolves, is extended with new features, becomes more complex. In this demo application, all the purple buttons trigger scenarios that could happen in real life. How do we make the app robust in all those scenarios?
- _The application accesses the database via the
Players
Swift Package.