How to Write Pragmatic, Testable Singletons in Swift
Singletons have their use. I use two Singletons regularly in my projects: a DomainPublisher
and a ServiceLocator
. The latter is a registry of service objects which is global so the service objects don’t have to be. For practical use, most Singletons are overcomplicated or overly restrictive. Here’s how I suggest you implement Singletons in your apps: