Overriding a stored property in Swift

前端 未结 10 809
鱼传尺愫
鱼传尺愫 2020-11-30 00:10

I noticed that the compiler won\'t let me override a stored property with another stored value (which seems odd):

class Jedi {
    var lightSaberColor = \"Bl         


        
10条回答
  •  佛祖请我去吃肉
    2020-11-30 00:37

    You also can use a function to override. It's not direct answer, but can enrich this topic)

    Class A

    override func viewDidLoad() {
        super.viewDidLoad()
    
        if shouldDoSmth() {
           // do
        }
    }
    
    public func shouldDoSmth() -> Bool {
        return true
    }
    

    Class B: A

    public func shouldDoSmth() -> Bool {
        return false
    }
    

提交回复
热议问题