Static vs class functions/variables in Swift classes?

前端 未结 9 1026
不知归路
不知归路 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:03

    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.

    Class :- reference type

    struct :- value type

提交回复
热议问题