To call a public static method on an instance of a class in Swift, you need to use the class name instead of the instance name, like so:
main.swift187 chars9 lines
In the example above, we define a class called MyClass
with a public static method called myStaticMethod
. Then we create an instance of MyClass
named myInstance
. To call the static method on the instance, we use the class name instead of the instance name (MyClass.myStaticMethod()
), since static methods belong to the class, not the instance.
gistlibby LogSnag