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

Jānis Kiršteins janis.kirsteins at gmail.com
Thu Jun 2 05:14:16 CDT 2016

I think you misunderstood my proposed syntax. To clarify:

enum Suit {
    let bezierPath: UIBezierPath // Stored property declaration

    case spades {
        let bezierPath = UIBezierPath() // Declare and initialize and
local variable, this is not stored property declaration
        // add drawing commands to bezierPath
        self.bezierPath = bezierPath // Initialize stored property
with local variable. Stored property is shared among cases

I agree that cases should not be treated as pseudo-type, I am not
proposing that. What I am proposing is the that enum instance
behaviour and data can be very dependent of it case. And that there
should be easier and clearer ways to configure that using stored

On Thu, Jun 2, 2016 at 10:26 AM, Brent Royal-Gordon
<brent at architechies.com> wrote:
>> 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
> Architechies

More information about the swift-evolution mailing list