[swift-evolution] Getting rid of willSet/didSet

Tino Heth 2th at gmx.de
Mon Dec 14 16:57:19 CST 2015

Hi there!

Considering that I just read that someone wants to have „willGet“, I guess willSet and didSet are here to stay — but for me, the concept has several downsides:
- two special keywords
- oldValue as another special word (there are some of those, but afaics only self and super are used often)
- imho it is not intuitive in which order those methods are called when subclassing
… and all those special rules only work for properties.

I think NS_REQUIRES_SUPER (beside the hard name) is much better, because
- it works for every method (I guess everyone knows some classes in Cocoa where the docs say you must call super, but the compiler cannot enforce this)
- order of execution is clear
- it is easy to block a change, instead of doing a rollback in „didSet“

The only advantage of willSet/didSet is that it is easy to create a stored property and be notified when it is changed, without the need to create an additional field — but I think it wouldn’t be that bad to just write „super.property = value“, even if there is no superclass as backing store: It may appear odd, but shouldn’t cause any problems.

Best regards,

More information about the swift-evolution mailing list