Variable with getter/setter cannot have initial value, on overridden stored property

In swift you are able to override properties only with computed properties (which are not able to have default values) with same type. In your case, if you wish override test property in SecondViewController you need write something like this:

override var test: Float {
    get {
        return super.test
    }
    set {
        super.test = newValue
    }
}

And there is no way to override didSet/willSet observers directly; you may do this by write other methods invoked in observers and just override them:

FirstViewController:

internal var test: Float = 32.0 {
    willSet {
        test_WillSet(newValue)
    }
    didSet {
        test_DidSet(oldValue)
    }
}

func test_WillSet(newValue: Float) {}
func test_DidSet(oldValue: Float) {}

SecondViewController:

override func test_WillSet(newValue: Float) {
    super.test_WillSet(newValue)
}
override func test_DidSet(oldValue: Float) {
    super.test_DidSet(oldValue)
}

Tags:

Swift