[swift-evolution] [Proposal] Enums with stored properties

Charles Srstka cocoadev at charlessoft.com
Wed Oct 12 17:44:17 CDT 2016


> On Oct 12, 2016, at 4:48 PM, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Since the definitions of the properties are implementation details, the generated interface would collapse to the simple list of cases and their associated values, just as methods, dynamic properties, etc. currently do.

I misspoke here; I meant to say that the *implementations* of the properties are implementation details. I.e. just as this:

struct MyStruct {
    var foo: String {
        return "Foo"
    }
    
    var bar: String {
        return "Bar"
    }
}

reduces to this:

internal struct MyStruct {

    internal var foo: String { get }

    internal var bar: String { get }
}

an enum declared like this:

enum MyEnum {
    var desc: String { get }
    
    case foo {
        desc = "Foo"
    }
    
    case bar {
        desc = "Bar"
    }
}

would reduce to this:


enum MyEnum {
    var desc: String { get }
    
    case foo
    case bar
}

The promise is that there will be a property named “desc” and that it will get you a string; that’s all that’s important to the interface.

Charles

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161012/ab0c2083/attachment.html>


More information about the swift-evolution mailing list