[swift-evolution] SE-0030 Property Behaviors

Антон Жилин antonyzhilin at gmail.com
Wed Feb 17 15:14:22 CST 2016


A second try at improving syntax for properties, aiming for unification and
consistency. This time I suggest to declare initialValue as an accessor, as
it is really an accessor with shorthand syntax. For this and a couple of
other ideas, please see the gist
<https://gist.github.com/Anton3/f71a3e2ee29dffe1b9b2>.

2016-02-14 15:41 GMT+03:00 Taras Zakharko <taras.zakharko at uzh.ch>:

> You are right! Ok, I’m convinced now as far as that goes :) Smart design.
> I didn’t think that far, I’m afraid.
>
> Thanks for explaining again,
>
>  T.
>
> > On 14 Feb 2016, at 13:33, Brent Royal-Gordon <brent at architechies.com>
> wrote:
> >
> >> This means that t1 and t2 should get two different initial values which
> is probably not what one would have intended.
> >
> > On the contrary, that's how initial values always work in Swift. Try it
> yourself: if you copy that code sample, delete the `[custom]`, and paste it
> into a Swift REPL (any version, as far as I know), it will print "2" and
> "3".
> >
> > This semantic is important in several cases, like assigning unique IDs,
> but it's perhaps most crucial when you're initializing with a reference
> type. When you write something like this:
> >
> >       struct Foo {
> >               let bar = NSMutableArray()
> >       }
> >
> > Each `Foo` needs to get its own, separate instance of NSMutableArray,
> rather than all of them sharing a single array. Reevaluating the initial
> value for every initialization achieves that goal.
> >
> > Given that it's the way the rest of the language works, I really don't
> think it'll be particularly surprising if this semantic carries over to
> property behaviors, too.
> >
> > --
> > Brent Royal-Gordon
> > Architechies
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160218/5b3a439d/attachment.html>


More information about the swift-evolution mailing list