I’ll be tomorrow a speaker at the Swift Paris meetup.
The topic is about Dependency Injection (DI).
And my part concerns “Dependency injection vs Singleton“.
We well know that iOS development (among other platforms) has often been reduced to the “Singletons Everywhere” principle.
Apple is the first one to have been using it a lot.
But with the legitimate reason that they are at a corner stone position and need to provide applications with their APIs.
But as a quick sneak of my talk:
one main issue with Singletons, among others, is the tight coupling.
That prevents classes to be easily or correctly unit tested.
You end up in using private methods to reset a singleton while test setup/tear down… yuck!
And Dependency Injection is an elegant way of passing dependencies depending on the context (hence the name ^^) and greatly reduce coupling!