Hacker News new | ask | show | jobs
by darbelo 4522 days ago
My favorite sight when I review iOS code for clients is seeing a method on the App delegate that 'preloads' a bunch of singletons in one go. It sets the tone for the rest of the trip.

In my experience, a large bunch of iOS developers tend to use singletons out of imitation. The "sharedWhatever" is the usual way for the framework to provide access to anything that is purposefuly single-instance[1]. Same thing with delegation, though that one is usually less cringe-worthy in practice.

[1] The "the accelerometer on your phone" kind of single-instance, which is a much more defensible use-case than what the typical iOS coder uses them for.

1 comments

So, have we decided on what would be a better approach for storing global state?

Static variables and methods? Pass the instance down to all children?

It seems like there's no hard and fast rule.

I dislike singletons, but will gladly make a static method + static var from time to time.