KrakenDev


Here's to the crazy ones. The misfits. The troublemakers. The Swifters.

Viewing entries tagged
singleton in swift

Defeating the Anti-Pattern Bully 💥 Part 1 - Singletons

In this inaugural post on my anti-pattern series, Defeating the Anti-Pattern Bully, I talk about singletons. Many blogs out there discourage the use of singletons and for the most part, I agree. However, that doesn't mean that they don't have their merits. Here, I'll show you where you should probably use them and why so many people say you shouldn't.

The Right Way To Write a Singleton

Due to the nature of a beta language, Swift didn't have all the right things it needed when it first started out. For instance, Singletons, over the course of the development of Swift from 1.0 to 1.2, gained several different implementations. Unfortunately, the proper way to write a singleton hasn't been propagated amongst the community yet due to the lack of documentation outlining how to write a singleton. What does "by virtue of let" mean anyways? How do we know our current implementation of a one line singleton satisfies the rules of being a singleton?