To add a static property to a class in Swift, you would define the property using the static
keyword. Here is an example:
main.swift108 chars6 lines
In this example, we define a static property named myStaticProperty
that belongs to the MyClass
class. This property can be accessed directly from the class itself, without the need to create an instance of the class:
main.swift59 chars2 lines
Note that static properties are shared across all instances of the class, and can be modified from any part of the program.
gistlibby LogSnag