[swift-evolution] RFC: didset and willset

Krystof Vasa kvasa at icloud.com
Thu May 19 02:02:32 CDT 2016


I don't see a cleaner solution for observing value change for a property on superclass:

class MyView: UIView {

	override var bounds: CGRect {
		didSet { 
			self._clearCachedValues() 
		}
	}

}

Without didSet, you need to do this:

class MyView: UIView {

	override var bounds: CGRect {
		get { 
			return super.bounds 
		}
		set { 
			super.bounds = newValue
			self._clearCachedValues() 
		}
	}

}

Which is just so painful to type out.

Krystof


> On May 19, 2016, at 8:37 AM, Tino Heth via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Because some posts explicitly stated the willSet/didSet-functionality should be kept (and I mentioned the option of discarding them):
> My statement had the same background as Brent's — I expect there will be a "cleaner" and more versatile replacement in the future, so "don't fix it if it isn't broken, and will be replaced soon anyways" ;-)
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list