overriding static vars in subclasses swift 1.2

后端 未结 4 1844
北海茫月
北海茫月 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:08

    You can use computed properties:

    class A {
       class var Name: String {
           return "A"
       }
    }
    
    class B: A {
       override class var Name: String {
           return "B"
       }
    }
    

    Usage:

    print(A.Name) // "A"
    print(B.Name) // "B"
    

提交回复
热议问题