<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">It just seems so obvious to create-if-nil, and makes it nice to reset stuff that should be re-created. In my case, after my NSURLSession gets invalidated, I wanted to set the property to nil, and next time a session was needed, it would just get created.<div><br></div><div>Sure, I can implement this myself, but ugh. <br><br><div id="AppleMailSignature">-- <div>Rick Mann</div><div><a href="mailto:rmann@latencyzero.com">rmann@latencyzero.com</a></div></div><div><br>On Oct 20, 2017, at 17:58, Jordan Rose <<a href="mailto:jordan_rose@apple.com">jordan_rose@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><div class="">It's not directly related to property behaviors. It was a bug that only worked with ImplicitlyUnwrappedOptional properties; we patched the type checker bug that led to it being allowed and didn't even notice until someone brought it up (<a href="https://bugs.swift.org/browse/SR-5172" class="">SR-5172</a>).</div><div class=""><br class=""></div><div class="">It would be possible to introduce this as an actual language feature even without the full property behaviors model, but we wouldn't want to just spell it 'lazy'. Maybe 'lazy_resettable' or something. And even though I say this, it's probably unlikely that such a proposal would get through swift-evolution in the Swift 5 timeframe.</div><div class=""><br class=""></div><div class="">Meanwhile, it's always possible to implement it by hand, though I can see how that'd be annoying if you were relying on this and previously got it with a single '!'.</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">class LazyResettableTest {</div><div class=""> private func fooInitial() -> String { return "initial value" }</div><div class=""> private var fooStorage: String?</div><div class=""> var foo: String! {</div><div class=""> get {</div><div class=""> if fooStorage == nil { fooStorage = fooInitial() }</div><div class=""> return fooStorage</div><div class=""> }</div><div class=""> set {</div><div class=""> fooStorage = newValue</div><div class=""> }</div><div class=""> }</div><div class="">}</div></blockquote><div class=""><br class=""></div>Jordan<div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Oct 19, 2017, at 19:59, David Sweeris 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 class="">I don't know. IIRC (big if), though, there was talk of adding support for "property behaviors"(?). Resetting lazy vars probably would've been one of them, and if so, it probably got pulled so that we wouldn't risk breaking source compatibility later by adding a consistent syntax for other behaviors. I think. I wish I could remember who'd brought up the idea... they'd probably know straight away if that's what happened.<br class=""><br class="">- Dave Sweeris<br class=""><br class=""><blockquote type="cite" class="">On Oct 19, 2017, at 5:40 PM, Rick Mann via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""><br class="">Googling for the answer, it seemed some versions of Swift supported setting a lazy var property to nil, such that the next time it's accessed, the initializer would be run again.<br class=""><br class="">But I just tried this in a playground in Swift 4 and it doesn't work.<br class=""><br class="">It sure seems to me like it should work. What's the reasoning for the current behavior?<br class=""><br class="">-- <br class="">Rick Mann<br class=""><a href="mailto:rmann@latencyzero.com" class="">rmann@latencyzero.com</a><br class=""><br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></blockquote><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-users">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></div></blockquote></div><br class=""></div></div></blockquote></div></body></html>