[swift-evolution] [Review] SE-0030 Property Behaviors

Curt Clifton curt at curtclifton.net
Fri Feb 19 01:05:10 CST 2016


On Feb 18, 2016, at 10:09 PM, Thorsten Seitz <tseitz42 at icloud.com> wrote:

>> Besides eliminating the odd naked “declaration”, this has the added advantage that it could be extended to `bind initialValue, propertyName`. :-)
> 
> Couldn't we just add a name by introducing an accessor to be implemented by the user of a property?

What would that look like? Would the programmer have to give the name of the property twice? Like so:

```
@plistBacked var warningTextColor: NSColor {
  name {
    return warningTextColor
  }
}
```

While that works as a stop gap, the repetition is an invitation to error. It would be much better to just write:

```
@plistBacked var warningTextColor: NSColor
```

and make the property's name available to the behavior's implementation, much as the property's declaring type is exposed as `self`.

But this is also largely off-topic for the thread. I was arguing for a better way to declare that initialValue should be bound and suggesting that a `bind` construct might be an approach that is extensible in the future.

Cheers,

Curt


More information about the swift-evolution mailing list