Hacker News new | ask | show | jobs
by UK-AL 4500 days ago
WTF?

You complain about singletons, then prefer a language where the use of [sharedInstance] is extremely common. Objective-C is singleton hell. Both in third party code, and core libaries.

C# is vastly nicer than objective-c, and I'm a iOS developer. I'd rather use C# or Scala with a IoC container to handle the lifetime of objects, rather than using singletons.

1 comments

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.

"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).