Swift Enum strings should not translate into objective c global static strings.<br><br>As I wrote in my proposal <br><br>( <a href="https://github.com/wh1pch81n/swift-evolution/blob/swift-enum-objc/proposals/NNNN-Swift-enum-strings-ported-to-Objective-c.md">https://github.com/wh1pch81n/swift-evolution/blob/swift-enum-objc/proposals/NNNN-Swift-enum-strings-ported-to-Objective-c.md</a> )<br><br>, we need to support a failable initializer.<br><br>I chose @objcstring to keep it consistent with how it would be used with struct for NS_EXTENSIBLE_STRING_ENUM. While an enum can inherit from String, a struct does not. So the evidence that this is meant to be used for strings is not there. That is why I suggest @objcstring to make that explicit and consistent between the two kinds.<br><br><br><br><div class="gmail_quote"><div dir="ltr">On Mon, Feb 20, 2017 at 7:33 PM Xiaodi Wu <<a href="mailto:xiaodi.wu@gmail.com">xiaodi.wu@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg">Agree. If technical limitations do not prohibit it, Kevin's idea seems the more elegant.</div><div dir="ltr" class="gmail_msg"><div class="gmail_extra gmail_msg"><br class="gmail_msg"></div><div class="gmail_extra gmail_msg"><br class="gmail_msg"><div class="gmail_quote gmail_msg">On Mon, Feb 20, 2017 at 6:28 PM, Kevin Nattinger via swift-evolution <span dir="ltr" class="gmail_msg"><<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br class="gmail_msg"><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg">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="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div style="margin:0px;line-height:normal" class="gmail_msg"><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// Already works</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">@objc</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">enum</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> IntEnum: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> {</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">case</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> foo = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="gmail_msg">1</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">case</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> bar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="gmail_msg">2</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">}</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal;min-height:13px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"></span><br class="gmail_msg"></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// "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="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// Should be allowed.</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">@objc</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">enum</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> StrEnum: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">String</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> {</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">case</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> foo</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">case</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> bar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">"baz"</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,0,0);margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">}</span></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Becomes</div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><br class="gmail_msg"></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// Current</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">typedef</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">NS_ENUM</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">(NSInteger, IntEnum) {</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> IntEnumFoo = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="gmail_msg">1</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">,</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> IntEnumBar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8" class="gmail_msg">2</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">};</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0);min-height:13px" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"></span><br class="gmail_msg"></div><div style="margin:0px;line-height:normal" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">// Proposed (static or extern, depending on implementation)</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">NSString</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> *</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">const</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> StrEnumFoo = </span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">@“foo"</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">;</span></div><div style="margin:0px;line-height:normal;color:rgb(0,0,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">NSString</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> *</span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">const</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"> StrEnumBar = </span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b" class="gmail_msg">@“baz"</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">;</span></div></div><div style="font-size:11px;font-family:Menlo;color:rgb(0,132,0)" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">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="gmail_msg"><br class="gmail_msg"><div class="gmail_msg"><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div class="m_-5266089227907475571h5 gmail_msg"><div class="gmail_msg">On Feb 20, 2017, at 4:07 PM, Derrick Ho via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-5266089227907475571m_-7285381567153374199Apple-interchange-newline gmail_msg"></div></div><div class="gmail_msg"><div class="gmail_msg"><div class="m_-5266089227907475571h5 gmail_msg"><div class="gmail_msg"><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_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_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg"></div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg 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="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg"></div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">@objcstring</div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">enum Planet {</div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"> case Jupiter</div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px">}</div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg"></div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg 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="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-5266089227907475571m_-7285381567153374199gmail_msg 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="m_-5266089227907475571m_-7285381567153374199gmail_msg 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="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg"></div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg 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="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg" style="color:rgb(49,49,49);word-spacing:1px"><br class="m_-5266089227907475571m_-7285381567153374199gmail_msg gmail_msg"></div><div class="m_-5266089227907475571m_-7285381567153374199gmail_msg 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></div></div>
_______________________________________________<br class="gmail_msg">swift-evolution mailing list<br class="gmail_msg"><a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg"></div></blockquote></div><br class="gmail_msg"></div></div></div><br class="gmail_msg">_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
<br class="gmail_msg"></blockquote></div><br class="gmail_msg"></div></div></blockquote></div>