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

Jānis Kiršteins janis.kirsteins at gmail.com
Thu Jun 2 01:50:18 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. But consider this:

struct Struct {
    static let bezierPath: UIBezierPath // shared

    static func initialize() {
        bezierPath = UIBezierPath()
    }
}

On Thu, Jun 2, 2016 at 12:18 AM, Brent Royal-Gordon
<brent at architechies.com> wrote:
>> UIBezierPath is shared for all instances of the enum case. So stored
>> properties are stored per case, not per instance (you have associated
>> values for per instance values).
>>
>>> that isn't really what this syntax suggests is happening
>>
>> Please explain what makes you think that way.
>
> Because you wrote `let bezierPath = UIBezierPath()` in the middle of a type definition, and in all other types, you would get a new bezier path for each instance.
>
>         struct Struct {
>                 let bezierPath = UIBezierPath()         // per instance
>         }
>         class Class {
>                 let bezierPath = UIBezierPath()         // per instance
>         }
>         func function() {
>                 let bezierPath = UIBezierPath()         // per call
>         }
>         enum Enum {
>                 case aCase {
>                         let bezierPath = UIBezierPath() // shared?!?!
>                 }
>         }
>
> --
> Brent Royal-Gordon
> Architechies
>


More information about the swift-evolution mailing list