[swift-evolution] Language enhancement: Nest enum declaration into protocol declaration

Derrick Ho wh1pch81n at gmail.com
Mon Nov 21 10:27:20 CST 2016


Jakub, try this...

struct WorkingEngine {
enum States {
case idle
}
}

Then you can call it

WorkingEngine.States.idle
On Mon, Nov 21, 2016 at 9:56 AM Karl Wagner via swift-evolution <
swift-evolution at swift.org> wrote:

> Proposal is being worked on.
> https://github.com/apple/swift-evolution/pull/552
>
> - Karl
>
>
>
>
> On Nov 21, 2016 at 1:33 pm, <Jakub Bednář via swift-evolution
> <swift-evolution at swift.org>> wrote:
>
> Hi fellow Swifters,
>
> I have just started using the language and was trying to declare an enum inside a protocol.
>
> protocol WorkingEngine {
>    enum States {
>   	Idle
>         Pending
>         Working
>         Finished
>         Canceled
>   }
>
>   var state: States { get }
> }
>
> The compiler refused this and I had to take the enum outside of the protocol:
>
> enum WorkingEngineStates {
>   	Idle
>         Pending
>         Working
>         Finished
>         Canceled
>   }
>
> protocol WorkingEngine {
>   var state: WorkingEngineStates { get }
> }
>
> This does not seem coherent with the rest of the language, as enums can be nested in classes, structs and even enums, but not to protocols.
> I haven’t found any proposal for this change. Is this the correct place to request it or get some opinion on the idea?
>
> Thanks a lot,
>
> Jakub
>
> _______________________________________________
> swift-evolution mailing list <listswift-evolution at swift.orghttps>
> swift-evolution at swift.org <listswift-evolution at swift.orghttps>
> https <listswift-evolution at swift.orghttps>://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161121/d55504ba/attachment.html>


More information about the swift-evolution mailing list