[swift-evolution] Getting rid of willSet/didSet

Adrian Kashivskyy adrian.kashivskyy at me.com
Tue Dec 15 02:57:27 CST 2015


I'm -1 on that, willSet and didSet are great tools for performing side effects (such as locking, for example). It was a major problem in Objective-C, as no easy solution (except overriding accessors) existed and still you'd have to write a lot of boilerplate code.

Pozdrawiam – Regards,
Adrian Kashivskyy

> Wiadomość napisana przez Nicky Gerritsen via swift-evolution <swift-evolution at swift.org> w dniu 15.12.2015, o godz. 08:50:
> 
> 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 work.
> Moreover, currently if creating a setter, you also need to supply a getter.
> 
> Regards,
> 
> Nicky
> 
> 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
> 
> _______________________________________________
> 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/20151215/a686f143/attachment.html>


More information about the swift-evolution mailing list