[swift-evolution] [Proposal] Enums with static stored properties for each case

Brent Royal-Gordon brent at architechies.com
Thu Jun 2 02:26:08 CDT 2016

> As stated before it supposed to be per case initialization. You cannot
> really have this analogy with other types as they have type and
> instance while enums have type, case and instance.

No. If structs have just type and instance, then so do enums.

Cases in enums are analogous to stored properties in structs: they are a means of organizing and representing concrete storage. They are not first-class entities in the way that types and instances are. Much mischief comes from thinking of cases as pseudo-types, or as some sort of peer to a type.

> But consider this:
> struct Struct {
>    static let bezierPath: UIBezierPath // shared
>    static func initialize() {
>        bezierPath = UIBezierPath()
>    }
> }

Yes, because there's a `static` keyword on that declaration. That marks it as something different from an ordinary `let`. Similarly, part of the idea of my use of accessors is that the `accessor` keyword marks it as something different from an ordinary `var`.

(Also, you shouldn't use `initialize()` in Swift; you should set the variable directly. Also also, I'm pretty sure that wouldn't work at all, because `initialize()` is a normal method, not an initializer, and `bezierPath` is a constant.)

Brent Royal-Gordon

More information about the swift-evolution mailing list