[swift-evolution] Getting rid of willSet/didSet
Charles Srstka
cocoadev at charlessoft.com
Tue Dec 15 10:45:24 CST 2015
> On Dec 15, 2015, at 1:23 AM, Tino Heth via swift-evolution <swift-evolution at swift.org> 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
-1 on this. As others have mentioned, willSet and didSet are extremely useful, and the above is a misuse of “super”, misleading the reader to suppose that UIView implements “foo”, when it does not.
Charles
More information about the swift-evolution
mailing list