<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I don't think we have any enum case attributes, but we do allow @objc on properties:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">import Foundation</div><div class=""><br class=""></div><div class="">class Test : NSObject {</div><div class="">&nbsp;&nbsp;@objc(foo) var foo, bar : Int</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">…it looks like it ends up applying to both of them, and then erroring that you get two of the same (via the selector conflict diagnostics). We can probably make this more principled (both for cases and in general).</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 10, 2015, at 11:30, Kevin Ballard &lt;<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">


<title class=""></title>

<div class=""><div class="">Do we have any attributes that are valid on enum cases today? If so, how do they handle this scenario?<br class=""></div>
<div class="">&nbsp;</div>
<div class="">I'm inclined to agree with you that it should be an error. It's reasonable to assume that an attribute on the declaration applies to all cases in the declaration, which is fine for most attributes, it just doesn't work for @objc(name) because it produces a name collision.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">I suspect the simplest approach here is to just figure out what the error message will be if you say<br class=""></div>
<div class="">&nbsp;</div>
<div class="">@objc(Foo) case Foo<br class=""></div>
<div class="">@objc(Foo) case Bar<br class=""></div>
<div class="">&nbsp;</div>
<div class="">and use the same error if you say<br class=""></div>
<div class="">&nbsp;</div>
<div class="">@objc(Foo) case Foo, Bar<br class=""></div>
<div class="">&nbsp;</div>
<div class="">-Kevin Ballard</div>
<div class="">&nbsp;</div>
<div class="">On Thu, Dec 10, 2015, at 07:22 AM, Harlan Haskins wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">An error seems reasonable here.<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><span class="font" style="font-family:Menlo">Error: Ambiguous Objective-C case name for ‘.Two’.</span><br class=""></div>
<div class="">&nbsp;</div>
<div class="">And then the Fix-It is just to put the second case on a new line and provide the <span class="font" style="font-family:Menlo">@objc(&lt;#name#&gt;)</span>&nbsp;completion.<br class=""></div>
<div class=""><div class="">&nbsp;</div>
<div class=""><blockquote type="cite" class=""><div class="">On Dec 10, 2015, at 1:56 AM, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div class=""><div class="">Does it make sense to put @objc(name) on enum cases? Such as<br class=""></div>
<div class="">&nbsp;</div>
<div class="">@objc enum Foo: Int {<br class=""></div>
<div class=""> &nbsp;&nbsp;&nbsp;@objc(kFooOne) case One<br class=""></div>
<div class=""> &nbsp;&nbsp;&nbsp;@objc(kFooTwo) case Two<br class=""></div>
<div class="">}<br class=""></div>
<div class="">&nbsp;</div>
<div class="">The only real problem here is what do we do if you say<br class=""></div>
<div class="">&nbsp;</div>
<div class="">@objc(kFooOne) case One, Two<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Either we just apply it to the One variant and ignore the Two variant, possibly with a warning, or we emit an error.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">-Kevin<br class=""></div>
<div class="">&nbsp;</div>
<div class="">On Wed, Dec 9, 2015, at 06:01 PM, Jordan Rose wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">&nbsp;</div>
<blockquote type="cite" class=""><div class="">On Dec 9, 2015, at 15:18, Kevin Ballard via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Swift allows for placing @objc on an enum that has an Int raw type in order to expose it to Obj-C. But it doesn't currently let you rename the enum when exposing it to Obj-C. This is particularly problematic when exposing a Swift enum that's nested in a struct/class, as the nesting resolves ambiguity in Swift but is not present in Obj-C.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Example:<br class=""></div>
<div class="">&nbsp;</div>
<div class="">import Foundation<br class=""></div>
<div class="">&nbsp;</div>
<div class="">class Foo: NSObject {<br class=""></div>
<div class=""> &nbsp;&nbsp;@objc enum Bar: Int {<br class=""></div>
<div class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case One, Two<br class=""></div>
<div class=""> &nbsp;&nbsp;}<br class=""></div>
<div class="">}<br class=""></div>
<div class="">&nbsp;</div>
<div class="">This generates the following:<br class=""></div>
<div class="">&nbsp;</div>
<div class="">SWIFT_CLASS("_TtC7unnamed3Foo")<br class=""></div>
<div class="">@interface Foo : NSObject<br class=""></div>
<div class="">- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;<br class=""></div>
<div class="">@end<br class=""></div>
<div class="">&nbsp;</div>
<div class="">typedef SWIFT_ENUM(NSInteger, Bar) {<br class=""></div>
<div class=""> BarOne = 0,<br class=""></div>
<div class=""> BarTwo = 1,<br class=""></div>
<div class="">};<br class=""></div>
<div class="">&nbsp;</div>
<div class="">I'd like to resolve this by saying @objc(FooBar) but that emits an error.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">I'm also going to submit a separate proposal saying we should change the default naming here so the enum is named FooBar, but these two proposals go hand-in-hand (there are cases where you might want to rename a root-level enum, to add a prefix for disambiguation in Obj-C, or you may want to selectively opt out of the proposed renaming rules by forcing your nested enum to use just its name in Obj-C).<br class=""></div>
</blockquote><div class="">&nbsp;</div>
<div class="">+1 to being able to rename @objc enums. I'm a little surprised we even allow exposing nested types to Objective-C, and am not at all sure the printer is set up to handle that correctly, but the renaming is independently useful.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Jordan<br class=""></div>
</blockquote><div class="">_______________________________________________<br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div>
</div>
</div>
</blockquote></div>
</div>
</blockquote><div class="">&nbsp;</div>
</div>

</div></blockquote></div><br class=""></body></html>