It recently came to my attention while working on a C-interop project that, as the title of this post suggests, imported C enums do not seem to conform to RawRepresentable
, though they have a rawValue
element. Is there a particular reasoning behind this?
Oversight. :-( We focused on NS_ENUM
and NS_OPTIONS
* in the early days of Swift and didn't put much effort into how regular, unannotated C enums came in. Now we'd have to think carefully about whether that'd be a backwards-compatible change.
* You can now get the same effect without importing Foundation using __attribute__((enum_extensibility(open)))
and __attribute__((flag_enum))
, plus __attribute__((enum_extensibility(closed)))
for NS_CLOSED_ENUM
.
1 Like
Thanks for the response; that is good to know. It would definitely be a nice QoL feature if C enums conformed to RawRepresentable, provided that the change wouldn't be source-breaking, but it isn't the biggest deal in the world.