[swift-users] strange property observer behavior

Jens Alfke jens at mooseyard.com
Sun Sep 4 13:45:42 CDT 2016

> On Sep 4, 2016, at 8:11 AM, adelzhang via swift-users <swift-users at swift.org> wrote:
> Swfit encourage to override the property observer. But when we change the own property in Child class's `didSet` observer, that would cause infinite loop:

I’m not a Swift guru, but that seems like a bug to me. The book explicitly says that it’s legal for a didSet block to set the property value, with no caveats about overridden properties.

You should be able to work around this by having the subclass override the `set` block instead, and pass the modified value to the superclass. (It’s probably slightly more efficient too.)


More information about the swift-users mailing list