[swift-evolution] Getting rid of willSet/didSet

Andrey Tarantsov andrey at tarantsov.com
Mon Dec 14 17:04:50 CST 2015


> 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.

It *is* odd, and I do the described didSet trick *all* the time.

Stuff like:

public class MyView: UIView {

  public var foo: Int {
    didSet {
      setNeedsDisplay()
    }
  }

  // ... ditto for 10 more properties ...

}

I would not appreciate that code getting any longer. It's such a relief after what I had to write in Objective-C!

A.



More information about the swift-evolution mailing list