Overriding properties

Hi,

Swift rules state that any inherited property can be overridden whether it is implemented as a stored or computed property at source (parent class).

I have been trying to illustrate this rule with an example, but Xcode kept throwing errors such as "cannot override with a stored property".

My deepest gratitude for helping me clarify this matter.

class ClassA {
    let constantStoredProperty: String = "Read-Only Behavior"
    var mutableStoredProperty: String = "Read-Write Behavior"
    var computedPropertyWithGet: String {
        get {
            return "Read-Only Behavior"
        }
    }
    var computedPropertyWithGetAndSet: String {
        get {
            return "Read-Write Behavior"
        }
        set {
            // some statements
        }
    }
}

class ClassB: ClassA {
    // overriding the 4 properties of ClassA
    
}
Terms of Service

Privacy Policy

Cookie Policy