[swift-evolution] Proposal: Allow willChange and didChange observers on a property
Mosab Elagha
elagha2 at illinois.edu
Sun Dec 6 00:42:47 CST 2015
+1. This feature would allow for a more clean approach in checking the
existing state of a value.
> Also, can a property have these observers as well as the existing ones?
I'm not really familiar with the implementation of the observers, but why
wouldn't it be able to? Maybe didSet can precede didChange in order of
execution if both are implemented, so you can have default behavior when
accessing a value but certain other behavior if it has changed. Or maybe
have willChange/didChange be a property that can be accessed within
willSet/didSet (like oldValue).
-Mosab Elagha
On Sun, Dec 6, 2015 at 12:11 AM, Chris Lattner via swift-evolution <
swift-evolution at swift.org> wrote:
>
> 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
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151206/bea982b4/attachment.html>
More information about the swift-evolution
mailing list