call a public static property on an instance of a class in swift

In Swift, you can call a public static property on an instance of a class by using the class name followed by the property name.

Here's an example:

main.swift
class MyClass {
    public static var myStaticProperty = "Hello, world!"
}

let myInstance = MyClass()
print(MyClass.myStaticProperty) // Output: "Hello, world!"
162 chars
7 lines

In this example, we define a class called MyClass with a public static property called myStaticProperty.

To access this property on an instance of the class, we simply use the class name (MyClass) followed by the property name (myStaticProperty).

The output of the program will be "Hello, world!", which is the value of the myStaticProperty property.

gistlibby LogSnag