Is ClassName.staticVaribale
the only way to access static variable within the class? I want something like self
, but for class. Like class.st
In a future Swift 3 version (yet to be released) you can use Self
(yes, that's with a capital) to reference to the containing class. A proposal for this was accepted, but the feature is not implemented yet.
For example:
struct CustomStruct {
static func staticMethod() { ... }
func instanceMethod() {
Self.staticMethod() // in the body of the type
}
}
Source: https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md