Static vs class functions/variables in Swift classes?

前端 未结 9 1045
不知归路
不知归路 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 17:55

    Adding to above answers static methods are static dispatch means the compiler know which method will be executed at runtime as the static method can not be overridden while the class method can be a dynamic dispatch as subclass can override these.

提交回复
热议问题