<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">This isn’t supposed to be supported, and you get a warning for it in Swift 4.1 (see <a href="https://bugs.swift.org/browse/SR-6165" class="">SR-6165</a>). I mentioned this in the fix:<div class=""><br class=""></div><div class=""><blockquote type="cite" class="">Arguably we could allow overriding with a stored property. The original concerns were that you could accidentally end up with extra storage you didn't need, and that observing accessors would behave differently based on whether or not the property was overriding. But there's at least no ambiguity for 'lazy', which can't have observing accessors today.<br class=""></blockquote><br class="">If you want to get this behavior, you can make a <i class="">second</i> private lazy property, and override the public property with a getter that just forwards to the lazy property.</div><div class=""><br class=""></div><div class="">Sorry for the confusion!</div><div class="">Jordan<br class=""><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 11, 2018, at 02:56, John Buckley via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I'm interested to know if overriding a lazy stored property in a sub-class is recommended or not. For example:<div class=""><br class=""></div><div class="">class CustomSegue: NSStoryboardSegue {</div><div class=""> lazy var animator: CustomAnimator()</div><div class=""><br class=""></div><div class=""> override func prepare() {</div><div class=""> ....</div><div class=""> }</div><div class="">}</div><div class=""><br class=""></div><div class="">class CustomSlideRightSegue: CustomSegue {</div><div class=""> override lazy var animator: CustomAnimator(.slideRight)</div><div class="">}</div><div class=""><br class=""></div><div class="">This works fine and the compiler does not complain. However:</div><div class=""><br class=""></div><div class="">1. Why is overriding lazy stored properties supported, while overriding a non-lazy stored property is not.</div><div class=""><br class=""></div><div class="">2. Is this behaviour intended and/or recommended.</div><div class=""><br class=""></div><div class="">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).</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">John</div></div>
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></div></div></body></html>