<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 10:11 PM, Chris Lattner <<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>> wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 4:00 PM, Nathan de Vries via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">It's currently possible to define either or both of the following observers on a property:<div class=""><ul class=""><li class=""><i class="">willSet</i>, called just before the value is stored</li><li class=""><i class="">didSet</i>, called immediately after the new value is stored</li></ul></div></div></div></blockquote><div class="">...</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">This would mean the following observers could be defined on a property:</div><div class=""><div class=""><ul class=""><li class=""><i class="">willSet</i>, called just before the value is stored</li><li class=""><i class="">willChange</i>, called just before the value is stored if the value is different to the previous value</li><li class=""><i class="">didSet</i>, called immediately after the new value is stored</li><li class=""><i class="">didChange</i>, called immediately after the new value is stored if the new value is different to the previous value</li></ul></div></div></div></div></blockquote></div><div class="">I’m open to consider a change along these lines, but the proposal would have to be fleshed out more. Presumably it would only work for equatable types, right?</div></div></div></blockquote><div><br class=""></div>I did a little hand-waving in that direction:</div><div><br class=""></div><div>"Property types conforming to Equatable would be checked for the implicit guard via ==, otherwise it would fall back on the identity operator (===) for value and reference types that don't conform to Equatable."</div><div><br class=""></div><div>Do you see an issue with falling back on identity if a property's type doesn't conform to Equatable?<br class=""><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Also, can a property have these observers as well as the existing ones?</div></div></div></blockquote><div><br class=""></div>I don't see any issue with someone deciding to exhaustively add all observers to a property, but practically I'd only expect a subset (one) of them to be implemented. In my case I'd almost exclusively use didChange.<br class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Would it be possible to add *one of* didChange or willChange - since less is better?</div></div></div></blockquote><div><br class=""></div>I never use willSet at the moment and can't imagine myself using willChange, so it was really only included for completeness. I'd be fine with limiting the addition to didChange only, with my only concern being the inconsistency of not providing willChange.</div><div><br class=""></div><div>—Nathan</div></body></html>