A self-educational iOS experiment to illustrate the difference between Singleton and Dependency Injection.
Swift - SwiftUI - Combine
MVVM
Singleton issues:
- They are Global and can be accessed anywhere in our app which is not desired.
- They can't swap out dependencies.
- They can't customize the init.
Dependency Injection can fix the above issues:
- The only classes that have access to our service will be ones that we are injection our service to them.
- It was by customising the init of our service in our Preview.
- By introducing protocol, we can fix the issue and swap between ProductionDataService and MockDataService.