static vs class as class variable/method (Swift)

In classes it's used for exactly the same purpose. However before Swift 1.2 (currently in beta) static was not available - the alternate class specifier was been made available for declaring static methods and computed properties, but not stored properties.


From the Xcode 3 beta 3 release notes:

“static” methods and properties are now allowed in classes (as an alias for “class final”).

So in Swift 1.2, hi() defined as

class foo {
  static func hi() {
    println("hi")
  }
}

is a type method (i.e. a method that is called on the type itself) which also is final (i.e. cannot be overridden in a subclass).

Tags:

Ios

Swift