Whether it is attacked as an anti-pattern, maligned as untestable, or misused as a global convenience, singletons take a lot of 💩 for just being what they are: a way to enforce that there is only ever one of something. I think they should call this pattern “The One”.
A real life example of a singleton is The President of the United States. We only ever have one president at a time. That’s a key part of the concept. It’s not just a convenience.
In software terms, singletons make sense in many cases such as the one and only instance of the current app running on the current iPhone.
With all this in mind, this quick post provides some nice context about singletons (aka the President) versus just a shared instance (hey, let’s all share this one bike) in Swift.
Thanks to iOS Dev Weekly for calling out the ongoing confusion on this topic. 🙏