New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-887] Expose the declaration order of Enum cases with payloads #43499
Comments
If an enum has a raw type, it doesn't just have a |
I guess it doesn't have to be a raw value. I was just trying to figure out a way to get the order of the cases with payloads with out having to create a helper function. |
Sounds like what you want is some function that takes any enum value and gives you the discriminant, similar to Rust's |
"discriminant" would be the wrong name here because (a) Swift doesn't guarantee to use unique discriminants if it can infer the info some other way, and (b) the order Swift allocates discriminants (deliberately) isn't guaranteed to match the order of declarations. (And with normal enums-with-raw-types you can manually set the raw values, but it sounds like you're okay with not doing that.) I don't think we have anything today that makes sense to expose at the user level, hence the LanguageFeatureRequest tag. This would need to go through the Swift Evolution Process, and I wouldn't call it "raw values" since it's not round-trippable. |
Sounds good. Thanks for the input Kevin and Jordan. I am going to wait a little bit until closer to swift 3-4. There are other things like getting all the cases that also would be nice to get for free. |
One of these proposals may be a requirement for this SR |
allCases solved this for me. |
1. That requires an O(N) search to find the index of a given case |
Additional Detail from JIRA
md5: 8985ba38c2b176524ace48d4f576b55c
Issue Description:
error:
"Enum with raw type cannot have cases with arguments"
In addition to being able to carry a payload, it would be really useful if enums could also have a way to expose their order as an Int or some sort of Index Raw type so they can be ranked by importance.
The text was updated successfully, but these errors were encountered: