[swift-evolution] [Proposal] Property behaviors

Joe Groff jgroff at apple.com
Wed Jan 13 20:04:44 CST 2016

> On Jan 13, 2016, at 5:12 PM, plx via swift-evolution <swift-evolution at swift.org> wrote:
> Quick Q1: is it the case that `var behavior redrawing<Value where Self:UIView> : Value { … } ` would work or no? I’d assume so, but I don’t think there are any examples with a non-protocol constraint on `Self`, making it hard to tell at a glance.

Yeah, you should be able to use arbitrary generic constraints.

> Quick Q2: is there anything you can do in this scenario:
> // w/in some behavior:
> mutating func silentlySet(value: Value) {
>  value = value // <- probably not going to work
>  self.value = value // <- not right either, `self` is the behavior’s owner, right?
> }
> …other than change the argument name to avoid conflict?

I thought I mentioned this in the proposal—you could use `behaviorName.value` to qualify a reference to the behavior's members within the behavior.

> Remark: it definitely feels a bit odd to be using both `Self` and `self` to mean something that’s neither consistent with the rest of the language nor, really, to mean `Self` (or `self`). 
> I get not wanting new keywords, but this feels like it could be an economy too far; perhaps I’m misunderstanding some aspect of how it’s meant to work.

I'm not totally comfortable with it either. It at least corresponds to the notion of `self` you'd get if you'd coded a property by hand within its enclosing type, so the meaning might be useful for refactoring code out of concrete property implementations into behavior templates.


More information about the swift-evolution mailing list