Static vs class functions/variables in Swift classes?

前端 未结 9 1050
不知归路
不知归路 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条回答
  •  猫巷女王i
    2020-11-28 17:50

    There's one more difference. class can be used to define type properties of computed type only. If you need a stored type property use static instead.

    "You define type properties with the static keyword. For computed type properties for class types, you can use the class keyword instead to allow subclasses to override the superclass’s implementation."

提交回复
热议问题