To call a static property on an instance of a class in Swift, you need to use the class name instead of the instance name.
Assuming you have a class named MyClass
with a static property called myStaticProperty
, here's an example of how to call it on an instance of the class:
main.swift195 chars7 lines
In this example, we create an instance of MyClass
called myInstance
and then access the static property myStaticProperty
using the class name MyClass.myStaticProperty
. The value of myStaticPropertyValue
will be "Hello, world!".
gistlibby LogSnag