<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="">I don’t think we need/want to add `@objcstring` or anything like that, but I do think we should let String enums be @objc (currently it’s int types only) and imported as const refs.<div class=""><br class=""></div><div class=""><div style="margin: 0px; line-height: normal;" class=""><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Already works</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@objc</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> IntEnum: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bar = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// "not an integer type"</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Should be allowed.</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">@objc</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures" class=""> StrEnum: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">String</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> foo</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> bar = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"baz"</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 0, 0); margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><br class=""></div><div class="">Becomes</div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><br class=""></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Current</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">typedef</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">NS_ENUM</span><span style="font-variant-ligatures: no-common-ligatures" class="">(NSInteger, IntEnum) {</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; IntEnumFoo = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span><span style="font-variant-ligatures: no-common-ligatures" class="">,</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; IntEnumBar = </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">};</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0); min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Proposed (static or extern, depending on implementation)</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSString</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">const</span><span style="font-variant-ligatures: no-common-ligatures" class=""> StrEnumFoo = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">@“foo"</span><span style="font-variant-ligatures: no-common-ligatures" class="">;</span></div><div style="margin: 0px; line-height: normal; color: rgb(0, 0, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">NSString</span><span style="font-variant-ligatures: no-common-ligatures" class=""> *</span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">const</span><span style="font-variant-ligatures: no-common-ligatures" class=""> StrEnumBar = </span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">@“baz"</span><span style="font-variant-ligatures: no-common-ligatures" class="">;</span></div></div><div style="font-size: 11px; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures;" class="">In fact, I’d go a step further and say any RawRepresentable enum as a globally initialized const in objc should be allowed the same treatment. Though the only other type that comes to mind is float/double.</span></div></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 20, 2017, at 4:07 PM, Derrick Ho via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">Swift should not forsake objective-c.&nbsp; At least not when it comes enum strings.&nbsp; Although swift enums are suppose to be swift only, I think we should add a new attribute to slightly relax that.&nbsp; I think a good attribute would be @objcstring.</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">By adding @objcstring, an objective-c exclusive class will be generated.</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">@objcstring</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">enum Planet {</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">&nbsp; case Jupiter</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">}</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">I have written up a proposal with more details on what it would look for objective-c.</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="gmail_msg"></div><a href="https://github.com/wh1pch81n/swift-evolution/blob/swift-enum-objc/proposals/NNNN-Swift-enum-strings-ported-to-Objective-c.md" class="gmail_msg" style="word-spacing:1px" target="_blank">https://github.com/wh1pch81n/swift-evolution/blob/swift-enum-objc/proposals/NNNN-Swift-enum-strings-ported-to-Objective-c.md</a><br class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">If no one objects to this proposal I'll submit it.</div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">**notes: I am reviving this discussion so that I may submit this for Swift 4 stage 2</div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></body></html>