<div dir="ltr">Agree. If technical limitations do not prohibit it, Kevin&#39;s idea seems the more elegant.<div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 20, 2017 at 6:28 PM, Kevin Nattinger via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">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><br></div><div><div style="margin:0px;line-height:normal"><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">// Already works</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">@objc</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">enum</span><span style="font-variant-ligatures:no-common-ligatures"> IntEnum: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">case</span><span style="font-variant-ligatures:no-common-ligatures"> foo = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">case</span><span style="font-variant-ligatures:no-common-ligatures"> bar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">2</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">// &quot;not an integer type&quot;</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">// Should be allowed.</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">@objc</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">enum</span><span style="font-variant-ligatures:no-common-ligatures"> StrEnum: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">String</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">case</span><span style="font-variant-ligatures:no-common-ligatures"> foo</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">    </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">case</span><span style="font-variant-ligatures:no-common-ligatures"> bar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b">&quot;baz&quot;</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)"><br></div><div>Becomes</div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)"><br></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)"><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">// Current</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">typedef</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">NS_ENUM</span><span style="font-variant-ligatures:no-common-ligatures">(NSInteger, IntEnum) {</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    IntEnumFoo = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">,</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">    IntEnumBar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">2</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">};</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;line-height:normal"><span style="font-variant-ligatures:no-common-ligatures">// Proposed (static or extern, depending on implementation)</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">NSString</span><span style="font-variant-ligatures:no-common-ligatures"> *</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">const</span><span style="font-variant-ligatures:no-common-ligatures"> StrEnumFoo = </span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b">@“foo&quot;</span><span style="font-variant-ligatures:no-common-ligatures">;</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">NSString</span><span style="font-variant-ligatures:no-common-ligatures"> *</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">const</span><span style="font-variant-ligatures:no-common-ligatures"> StrEnumBar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b">@“baz&quot;</span><span style="font-variant-ligatures:no-common-ligatures">;</span></div></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">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><br><div><blockquote type="cite"><div><div class="h5"><div>On Feb 20, 2017, at 4:07 PM, Derrick Ho via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-7285381567153374199Apple-interchange-newline"></div></div><div><div><div class="h5"><div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">Swift should not forsake objective-c.  At least not when it comes enum strings.  Although swift enums are suppose to be swift only, I think we should add a new attribute to slightly relax that.  I think a good attribute would be @objcstring.</div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-7285381567153374199gmail_msg"></div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">By adding @objcstring, an objective-c exclusive class will be generated.</div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-7285381567153374199gmail_msg"></div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">@objcstring</div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">enum Planet {</div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">  case Jupiter</div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">}</div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-7285381567153374199gmail_msg"></div><div class="m_-7285381567153374199gmail_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="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-7285381567153374199gmail_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="m_-7285381567153374199gmail_msg" style="word-spacing:1px" target="_blank">https://github.com/wh1pch81n/<wbr>swift-evolution/blob/swift-<wbr>enum-objc/proposals/NNNN-<wbr>Swift-enum-strings-ported-to-<wbr>Objective-c.md</a><br class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-7285381567153374199gmail_msg"></div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">If no one objects to this proposal I&#39;ll submit it.</div><div class="m_-7285381567153374199gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-7285381567153374199gmail_msg"></div><div class="m_-7285381567153374199gmail_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></div></div>
______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br></div></blockquote></div><br></div></div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div></div>