[swift-evolution] Proposal: Allow @objc(name) on enum declarations

Kevin Ballard kevin at sb.org
Fri Dec 11 23:40:11 CST 2015


On Fri, Dec 11, 2015, at 02:39 PM, Douglas Gregor wrote:
>
>> On Dec 11, 2015, at 1:19 PM, Kevin Ballard via swift-evolution <swift-
>> evolution at swift.org> wrote:
>>
>> I've now submitted this proposal as a PR:
>> https://github.com/apple/swift-evolution/pull/50
>
> Thanks for writing this up!
>
> I was actually surprised that this didn’t already work; @objc is
> supposed to be able to rename effectively anything at this point.
> Given that, and that another core team member has already +1’d, we
> can skip the evolution process and call this a bug fix. Want to
> contribute a fix?

I'd love to! I'll start working on one over the weekend.

>> I listed one open question:
>>
>> Should the generated Obj-C declarations use the swift_name attribute
>> to indicate the Swift type it came from? Proposal SE-0005 generalizes
>> swift_name to apply to any arbitrary C or Obj-C entity, so it will be
>> legal to put on enums.
>>
>> Labelling it makes it clear to the reader what the Swift equivalent
>> is, but I'm unsure if there's any downsides to doing this.
>
> Yes, it makes sense to use the swift_name attribute here. If you’re
> implementing your proposal, check out
> lib/PrintAsObjC/PrintAsObjC.cpp and how we use the
> SWIFT_COMPILE_NAME macro for this in the generated header.

Will do. My worry with using swift_name is that, at least in the clang
that ships with Xcode 7.2, you can't actually put the swift_name
attribute on an enum. I assume that will change with SE-0005, but I also
assume this hasn't been implemented yet. And even when it is
implemented, emitting it will be a backwards-compatibility hazard if the
generated header needs to work with older clangs. Is there any way to
suppress the error?

I'm also not sure offhand where you actually put the attribute on an
enum, since the enum definition is actually 2 declarations, one for the
typedef and one for the enum itself. Would it go after the `enum`
keyword, in the place where SWIFT_ENUM_EXTRA is?

-Kevin Ballard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151211/139c9030/attachment.html>


More information about the swift-evolution mailing list