Hacker News new | ask | show | jobs
by d0 4504 days ago
Yes exactly that.

The difference is that your Objective-C/iOS application doesn't consist of thousands of threads which require synchronised access to these objects. It's a pretty static thing with an event loop. Possible a couple of background worker threads.

For a desktop application or even mobile application it's fine but for a massively scalable back-end enterprise system it's a pain in the butt.

Singletons are not for managing lifetime as well. They are a container for an object -- nothing else. Lifetime should be managed separately i.e using a container/service locator or something. Everything I've seen Cocoa-wise is pretty decoupled so far. There are some crimes but only inexperience seems to require them.

1 comments

"Singletons are not for managing lifetime as well" - No, but you can replace it with something that does. I.E Single Object with application lifetime vs singleton.
Or a singleton that exposes a service locator (which is the pattern I've been using in Cocoa).