Actually this is very consistent. You can not nest data structures like enums, structs, or classes in a protocol. This is because a protocol is meant to be a list of variables and functions that data structures may conform to. A protocol is not a data structure.<br><div class="gmail_quote"><div dir="ltr">On Mon, Nov 21, 2016 at 7:33 AM Jakub Bednář via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi fellow Swifters,<br class="gmail_msg">
<br class="gmail_msg">
I have just started using the language and was trying to declare an enum inside a protocol.<br class="gmail_msg">
<br class="gmail_msg">
protocol WorkingEngine {<br class="gmail_msg">
enum States {<br class="gmail_msg">
Idle<br class="gmail_msg">
Pending<br class="gmail_msg">
Working<br class="gmail_msg">
Finished<br class="gmail_msg">
Canceled<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
var state: States { get }<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
The compiler refused this and I had to take the enum outside of the protocol:<br class="gmail_msg">
<br class="gmail_msg">
enum WorkingEngineStates {<br class="gmail_msg">
Idle<br class="gmail_msg">
Pending<br class="gmail_msg">
Working<br class="gmail_msg">
Finished<br class="gmail_msg">
Canceled<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
protocol WorkingEngine {<br class="gmail_msg">
var state: WorkingEngineStates { get }<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
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.<br class="gmail_msg">
I haven’t found any proposal for this change. Is this the correct place to request it or get some opinion on the idea?<br class="gmail_msg">
<br class="gmail_msg">
Thanks a lot,<br class="gmail_msg">
<br class="gmail_msg">
Jakub<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>