[swift-users] Override Lazy Stored Property

John Buckley john at olivetoast.com
Thu Jan 11 04:56:20 CST 2018

I'm interested to know if overriding a lazy stored property in a sub-class
is recommended or not. For example:

class CustomSegue: NSStoryboardSegue {
    lazy var animator: CustomAnimator()

    override func prepare() {

class CustomSlideRightSegue: CustomSegue {
     override lazy var animator: CustomAnimator(.slideRight)

This works fine and the compiler does not complain. However:

1. Why is overriding lazy stored properties supported, while overriding a
non-lazy stored property is not.

2. Is this behaviour intended and/or recommended.

3. I realise you can achieve the same result by overriding init in the
sub-class and assigning to a non-lazy property, however often this reduces
clarity and introduces un-necessary boiler-plate code (especially if init
takes a number of args).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20180111/3c0ae02b/attachment.html>

More information about the swift-users mailing list