Hopefully this will stem the tide of questions on Stack Overflow about different Objective-c singleton implementations.
Hopefully this will stem the tide of questions on Stack Overflow about different Objective-c singleton implementations.
I'm also interested in hearing what is considered the best practice for things like passing around config options, an eventloop, or message bus.
When you DO need global state, then a singleton object is a reasonable way to achieve it. But chances are fairly high that you don't.
As I'm not in the mobile sphere, I wouldn't know how to avoid a singleton for an app that is constrained by speed and space requirements. I've already shown an example above, what's your solution in this environment, with the constraints of the questioner?
If he's making a game, this is completely acceptable design. Games programming is wildly different from application or server programming. Also, strict TDD is much, much less useful in games programming than anywhere else. Writing unit tests for central data structures and algorithms is useful, of course, but the majority of modules/classes/objects are so small, uncritical, and change completely so often that it's not worth bothering.