Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-09 Thread Rick Mann via swift-users
> On Aug 9, 2016, at 08:24 , Karl wrote: > > >> On 3 Aug 2016, at 02:01, Rick Mann via swift-users >> wrote: >> >> It complains if I make it a let because computed properties must be var. >> Because it's a protocol, it can't be stored (even though it can be stored in >> the conforming type

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-09 Thread Karl via swift-users
> On 3 Aug 2016, at 02:01, Rick Mann via swift-users > wrote: > > It complains if I make it a let because computed properties must be var. > Because it's a protocol, it can't be stored (even though it can be stored in > the conforming type). > > If I make it { get }, I can't set it in the ex

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-09 Thread Dan Loewenherz via swift-users
On Mon, Aug 8, 2016 at 6:16 PM, Rick Mann wrote: > > > On Aug 3, 2016, at 03:23 , Dan Loewenherz wrote: > > > > On Wed, Aug 3, 2016 at 3:51 AM, Rick Mann via swift-users < > swift-users@swift.org> wrote: > > > > > On Aug 2, 2016, at 19:06 , Jordan Rose wrote: > > > > > > I don’t think it makes

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-08 Thread Rick Mann via swift-users
> On Aug 3, 2016, at 03:23 , Dan Loewenherz wrote: > > On Wed, Aug 3, 2016 at 3:51 AM, Rick Mann via swift-users > wrote: > > > On Aug 2, 2016, at 19:06 , Jordan Rose wrote: > > > > I don’t think it makes sense to do this. A protocol cannot control how a > > particular property is implement

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-03 Thread Dan Loewenherz via swift-users
On Wed, Aug 3, 2016 at 3:51 AM, Rick Mann via swift-users < swift-users@swift.org> wrote: > > > On Aug 2, 2016, at 19:06 , Jordan Rose wrote: > > > > I don’t think it makes sense to do this. A protocol cannot control how a > particular property is implemented (stored or computed), and any conform

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-03 Thread Rick Mann via swift-users
> On Aug 2, 2016, at 19:06 , Jordan Rose wrote: > > I don’t think it makes sense to do this. A protocol cannot control how a > particular property is implemented (stored or computed), and any conforming > type must initialize all of its stored properties before returning from its > own initia

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-02 Thread Jordan Rose via swift-users
I don’t think it makes sense to do this. A protocol cannot control how a particular property is implemented (stored or computed), and any conforming type must initialize all of its stored properties before returning from its own initializer. (You can’t write an initializer in a protocol that doe

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-02 Thread David Sweeris via swift-users
Oh, it's a computed property! Got it, I thought you meant its value was computed in the init and never changed again. Sent from my iPhone > On Aug 2, 2016, at 19:01, Rick Mann wrote: > > It complains if I make it a let because computed properties must be var. > Because it's a protocol, it can

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-02 Thread Rick Mann via swift-users
It complains if I make it a let because computed properties must be var. Because it's a protocol, it can't be stored (even though it can be stored in the conforming type). If I make it { get }, I can't set it in the extensions init() method. I guess I could make it private set (not sure of the

Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-02 Thread David Sweeris via swift-users
If I understand things correctly, you *can* make uuid a let because you’re allowed to set them (once) during init functions. - Dave Sweeris > On Aug 2, 2016, at 6:22 PM, Rick Mann via swift-users > wrote: > > I'm trying to define a protocol that has a read-only, immutable member "uuid" > tha

[swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-02 Thread Rick Mann via swift-users
I'm trying to define a protocol that has a read-only, immutable member "uuid" that can be set in the init() method, but I'm having trouble. I have this: protocol Element { var uuid : { get } } extension Element { init(...) { self.uuid = ... } } I can't make it let, becau