overriding static vars in subclasses swift 1.2

后端 未结 4 1840
北海茫月
北海茫月 2021-01-07 16:58

unlike class var, where they can overridden in subclasses, I believe same applies to static as well but unfortunately not. Here\'s an example

4条回答
  •  时光说笑
    2021-01-07 17:05

    As suggested, you cannot override static variables but can use class (static) function to override.

    class A {
       class func StaticValue() -> AnyObject {
          return "I am a String"
       }
    }
    
    class B: A {
        override class func StaticValue() -> AnyObject {
            return 2
        }
    }
    

提交回复
热议问题