<div dir="ltr">:) Wasn't expecting it to be trivial. but yeah if it could somehow be short circuited so didSet, willSet isn't called when there is a value already. that would be awesome.<div><br></div><div>Could the willSet, didSet behaviour be tied to the = behaviour ? in your example above the operation ultimately cascades into a = operation. </div><div><br></div><div>Same with operations such as *= or /= ultimately it has to do a = operation to set the new calculated value.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 15, 2015 at 11:23 PM, Jacob Bandes-Storch <span dir="ltr"><<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I agree that would be nice. Just pointing out that it's nontrivial. If you implement this custom operator today, you get different behavior.<div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div><div dir="ltr"><div>Jacob<br></div></div></div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Tue, Dec 15, 2015 at 3:21 PM, James Campbell <span dir="ltr"><<a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">If it has a value already the nit wouldn't call anything as it technically hasn't been set. Only if it already has a value does it try and set something in which case the didSet is called :)</div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Tue, Dec 15, 2015 at 11:16 PM, Jacob Bandes-Storch via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr">One possible caveat is with custom setters.<div><br></div><div>If "a" already has a value, does "a ??= b" call the custom setter/willSet/didSet, or does it see the nil and short-circuit?</div><div><br></div><div>This can be implemented today:</div><div><br></div><div> func ??=(inout lhs: T?, @autoclosure rhs: () -> T?) { if lhs == nil { lhs = rhs() } }</div><div><br></div><div>However, the use of "inout" will always cause the didSets to be triggered at the call site, when just using if-statements instead wouldn't have done so.</div><div class="gmail_extra"><br clear="all"><div><div><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote"><div><div>On Tue, Dec 15, 2015 at 3:10 PM, Brent Royal-Gordon via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><span>> I think that the existing syntax for “??” handles this need fairly well without requiring an additional assignment operator:<br>
><br>
> a = a ?? []<br>
<br>
</span>When the variable is `a`, sure. When it’s `scoreboardViewController.selectedScoreboard`, not so much.<br>
<br>
+1 from me, though I prefer the `??=` spelling to match the `??` operator more closely.<br>
<span><font color="#888888"><br>
--<br>
Brent Royal-Gordon<br>
Architechies<br>
</font></span></div></div><div><div><br><span>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</span></div></div></blockquote></div><br></div></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xV0JY-2FdZMnUMvSFtZnLiBPRTDDOSQf3-2FpH33HYOlBxHCmoqblRPu3QCZ5XRZruwnZ-2BGlsSXS7XHFBVRQTA-2B5NKBPecSkEMiEKqvTO5Loxd1XRhCgv-2BUMspC3PpyoJKT32QJ8AjHhSDZoG8JxbSxNRa0gU66lqARiwCJSzRUqw9vcSIIUcROAn9fZ1PyPletwh1fvNW7gUOt2JnzR-2FY7Cea7ouGlsomTcq5O1idJnkvA-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
<br><span>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></span></blockquote></div><br><br clear="all"><span><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank">+44 7523 279 698</a></div></div></div></div></div></div>
</span></div>
</blockquote></div><br></div></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div>