[swift-evolution] Proposal: Allow willChange and didChange observers on a property

Chris Lattner clattner at apple.com
Sun Dec 6 00:11:21 CST 2015


> On Dec 5, 2015, at 4:00 PM, Nathan de Vries via swift-evolution <swift-evolution at swift.org> wrote:
> 
> It's currently possible to define either or both of the following observers on a property:
> willSet, called just before the value is stored
> didSet, called immediately after the new value is stored
...

> This would mean the following observers could be defined on a property:
> willSet, called just before the value is stored
> willChange, called just before the value is stored if the value is different to the previous value
> didSet, called immediately after the new value is stored
> didChange, called immediately after the new value is stored if the new value is different to the previous value

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?  Also, can a property have these observers as well as the existing ones?  Would it be possible to add *one of* didChange or willChange - since less is better?

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151205/9d9fb9ba/attachment.html>


More information about the swift-evolution mailing list