[swift-evolution] Overriding computed properties with let constants?

Roman Zhikharevich rzhikharevich at icloud.com
Sat Apr 23 06:11:43 CDT 2016


I think, it could be a good idea to make computed properties overridable with let constants.

Something like this:

class Parent {
    var x: Int {
        let x = 42
        /*
         * Compute x...
         */
        return x
    }
}

class Child: Parent {
    /*
     * Sometimes you need to override computed properties with simple constants.
     * This is currently done like this.
     */
    //override var x: Int {return 7}
    
    /*
     * But this looks neater.
     * Currently this gives "error: cannot override with a stored property 'x'".
     */
    override let x = 7
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160423/aa9e0779/attachment.html>


More information about the swift-evolution mailing list