Quick override func class

Easy to override a method in Swift:

class A {
   func innerValue() -> Int { return 5 }
   func getInnerValue() -> Int { return innerValue() }
}

class B: A {
   override func innerValue() -> Int { return 8 }
}

B().getInnerValue() //returns 8

However, I do not know how to do the same when I declare innerValue()as static (using the keyword class):

class A {
   class func innerValue() -> Int { return 5 }
   func getInnerValue() -> Int {
      return A.innerValue() //ok for compiler but returns 5 instead of 8
      return self.innerValue() //error: 'A' doesn't have a member named 'innerValue'
      return innerValue() //error: Use of unresolved identifier 'innerValue'
   }
}

class B: A {
   override class func innerValue() -> Int { return 8 }
}

B().getInnerValue()

So is it possible in Swift?

+4
source share
1 answer
return A.innerValue() //ok for compiler but returns 5 instead of 8

, . , innerValue() A; A. self, , , getInnerValue - , , , - . self.dynamicType, .

+7

All Articles