Static vs class functions/variables in Swift classes?

前端 未结 9 1040
不知归路
不知归路 2020-11-28 17:13

The following code compiles in Swift 1.2:

class myClass {
    static func myMethod1() {
    }
    class func myMethod2() {
    }
    static var myVar1 = \"\"         


        
9条回答
  •  情话喂你
    2020-11-28 18:07

    static and class both associate a method with a class, rather than an instance of a class. The difference is that subclasses can override class methods; they cannot override static methods.

    class properties will theoretically function in the same way (subclasses can override them), but they're not possible in Swift yet.

提交回复
热议问题