-5

In Swift, if I have a class with only type properties and methods (everything declared static) would that be considered a singleton object? If not, why?

0

1 Answer 1

1

This isn't specific to Swift at all.

You don't have an object, you don't have an instance of the class, therefore you don't have the singleton.

The essence of the singleton object is that it is the sole instance of a class. Exactly one instance. Not two, not three, not zero. One instance. You have zero instances, therefore you don't have a singleton object.

1
  • Well, in languages where classes are objects and are singleton instances of their metaclass (e.g. Smalltalk), one could make the argument that it is a singleton. I don't know enough about Swift, though, to tell whether or not that is the case here. Jun 30, 2017 at 7:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.