You can only use the computed variable with both setter
and getter
to overriding the stored property of the superclass. I got this conclusion by trying the following code. I'm not sure I'm 100% correct. Please correct me if I'm wrong. Thanks!
class SuperClass {
var ID = 2202
}
//Wrong
class SubClass: SuperClass {
override var ID = 2203
}
//worng
class SubClass: SuperClass {
override var ID: Int {
return super.ID + 1
}
}
//Correct
class SubClass: SuperClass {
override var ID: Int {
get {
return super.ID + 1
}
set {
}
}
}