Most of the Swift MVVM examples I came across use Dependency Injection to inject Model into ViewModel, and then ViewModel into the ViewController. This injection is normally recommended to be handled in AppDelegate as its a singleton. Thats all fine for simple examples.
However in real world the "model" is actually more than just a DTO object, it assumes Business & Data Layers that return the model / DTO. So injecting the model into the ViewModel on AppDelegate level is unrealistic as the View/ViewController will trigger actual data refreshes. So the model injection needs to happen elsewhere.
Furthermore, most examples go directly from ViewModel to DataAccess, which results in the ViewModel taking in lots of business logic, when ideally it should just hold the state for the view.
Could someone forward a comprehensive end-to-end Swift MVVM example with discretely separated Business & Data Layers. To keep this question not opinion based but in question/answer format, the example should have:
- Separate Business Logic Layer
- Separate Data Access Logic Layer
- Separate Model / DTO (state-only object)
The example should also illustrate clearly:
- Where Dependency Injection takes place
- Have clearly defined call hierarchy between above defined layers