Over time, Apple has given us quite a few tools that make graphic design easier for us to do in our own apps. Unfortunately, we've come to rely on our fellow graphic designers to do a lot of the grunt work for us, even though tools like Xcode 6 give us the capability to do it ourselves. Hopefully, with this article, we can learn some things that can prevent our fellow graphic designers from going postal and doing things like printing out 1x, 2x, and 3x image assets on paper and stapling them to our faces.
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.
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?
Subclassing can suck. There are so many ways to get it wrong and it's so easy to fall into anti-patterns when you create such a tight coupling between two classes. Most of the time, the need for subclassing can actually be replaced by abstraction through protocol-oriented, value-oriented, and functional programming. In fact, I may even argue that doing it that way can far outweigh the "benefits" of subclassing the majority of the time.
Quite often we find ourselves marking our code with TODOs, FIXMEs, and ERRORs only to find some of them forgotten about and left by the wayside. In Objective-C, it was easy to mark these tags and have them show up in the Issue Navigator but since the introduction of Swift, we haven't gotten an equivalent to compiler directives that can do the equivalent. Until now.