There are some posts for how to write code for static constant
and static variable
in Swift. But it is not clear when to use static constant<
Static constants and variables do belong to the class itself, not to a particular instance. A class can also have static methods that can be called without creating an instance of a class.
So when you have a class MyClass
with a static var x
, you can also access it through MyClass.x
directly. x
will be shared among all instances of a class