[ad_1]
Though there is no technical motive why you can’t override a property with one which introduces storage (though it might increase ambiguities with observer overrides; see this Q&A for more information), Swift would not at the moment permit you to take action.
The truth that in 4.0 you would override a property with a lazy property was unintended (because the override introduces storage), and so you will get a warning in 4.1 and an error in Swift 5 mode with a purpose to protect supply compatibility (applied in #13304).
You may nonetheless obtain the identical end result with a forwarding computed property although:
class A {
lazy var myVar: String = "A"
}
class B : A {
// Observe that this is not a particulary compelling case for utilizing 'lazy', as
// the initialiser expression will not be costly.
personal lazy var _myVar: String = "B"
override var myVar: String {
get { return _myVar }
set { _myVar = newValue }
}
}
[ad_2]
