<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="">Ah, to be clear, it's not that stored properties can't be overridden, it's that the <i class="">override</i> can't introduce new storage. (I think you got that, but didn't want a passerby to be confused.)<div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 12, 2018, at 09:09, John Buckley <<a href="mailto:john@olivetoast.com" class="">john@olivetoast.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><span style="font-size:small" class="">Hi Jordan,</span><div style="font-size:small" class=""><br class=""></div><div style="font-size:small" class="">Thanks for the explanation - much appreciated.</div><div style="font-size:small" class=""><br class=""></div><div style="font-size:small" class="">It's a shame stored properties can't be overridden, but I can see how there are issues around observers etc.</div><div style="font-size:small" class=""><br class=""></div><div style="font-size:small" class="">For now I've switched to a private backing property and a factory method, similar to what you suggested.</div><div style="font-size:small" class=""><br class=""></div><div style="font-size:small" class="">John</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, 11 Jan 2018 at 18:51 Jordan Rose <<a href="mailto:jordan_rose@apple.com" class="">jordan_rose@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;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" target="_blank" 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=""></div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class="">Jordan<br class=""></div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><div class=""><div 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" target="_blank" class="">swift-users@swift.org</a>> wrote:</div><br class="m_-270645340190409470Apple-interchange-newline"></blockquote></div></div></div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><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></div></blockquote></div></div></div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><div class=""><div class=""><blockquote type="cite" class=""><div class="">
_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote></div></div></div></div></blockquote></div>
</div></blockquote></div><br class=""></div></body></html>