[swift-evolution] Getting rid of willSet/didSet

Nicky Gerritsen nickygerritsen at me.com
Tue Dec 15 01:50:05 CST 2015

But how does this work if `super` does not have `foo`, exactly like in 
this example? UIView does not have a member named `foo`, so it will not 
Moreover, currently if creating a setter, you also need to supply a getter.



On 12/15/2015 08:23 AM, Tino Heth via swift-evolution wrote:
>> It *is* odd, and I do the described didSet trick *all* the time.
>> Stuff like:
> The alternative wouldn’t be that complicated:
> public class MyView: UIView {
> 	public var foo: Int {
> 		set(value) {
> 			super.foo = value
> 			setNeedsDisplay()
> 		}
> 	}
> }
> It’s just one line more, but three(!) keywords less that could be removed from the language; and I bet in the wild there are many thousand errors in subclasses of UIViewController that happen because the author didn’t remember wether he has to call super in viewDid…, loadView etc.
> _______________________________________________
> 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