<html><head><meta http-equiv="Content-Type" content="text/html charset=iso-8859-1"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Oh, you can certainly define a macro named NS_ENUM yourself, but that doesn't really seem like the right thing to do on Linux.</div><div class=""><br class=""></div><div class="">As for why we can't "guess" that this is a true enum, consider the following:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">enum Foo {</div><div class="">&nbsp; A = 1,</div><div class="">&nbsp; B = 2,</div><div class="">};</div></blockquote><div class=""><br class=""></div><div class="">Is this a very small option set, or an enum that deliberately doesn't start at 0? Or just a way to define constants for some other type, rather than using "static const"? If the compiler guesses here, (a) it might guess wrong, making the type hard to use <i class="">now,</i>&nbsp;and (b) if the headers are updated in a newer version of the library, it might <i class="">change</i>&nbsp;its guess, which would break source compatibility. (This can happen anyway, e.g. the first time an annotation is added, but at least that's supposed to be changing in the right direction, and is unlikely to change again.)</div><div class=""><br class=""></div><div class="">Hope that clarifies the motivation here, even if it's less than satisfactory.</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 Jan 11, 2016, at 11:22, Ryan Lovelett &lt;<a href="mailto:swift-dev@ryan.lovelett.me" class="">swift-dev@ryan.lovelett.me</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">


<title class=""></title>

<div class=""><div class="">Jordan,<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Perhaps I'm not following that parenthetical comment. Are you saying that even if I could add <span class="highlight" style="background-color: rgb(255, 255, 255)"><span class="colour" style=""><span class="font" style="font-family:Menlo, monospace"><span class="size" style="font-size:12px">NS_ENUM&nbsp;</span></span></span></span>to the header it still wouldn't compile into a true Swift enum (on a non-Apple platform)?<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Swift's pattern matching capability is probably a top 3 reason why I am trying to port my C application to use Swift rather than just straight C. Not being able to get this nicety out-of-the-box is just part of doing business on a bleeding edge programming language.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">However this&nbsp;<i class="">seems</i> like something that should be able to be achieved. Looking at the fe_type enum definition, because it had no bit pattern associated with it, I would have assumed it was a true non-overlapping enum. Its probable I'm not seeing the whole landscape here so would you be able to illuminate why isn't this the default?<br class=""></div>
<div class="">&nbsp;</div>
<div class="">On Mon, Jan 11, 2016, at 01:11 PM, Jordan Rose wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">Right. This is because Swift can't tell if your enum is actually an option set, a true, non-overlapping enum, or just a set of related constants, so it picks the lowest common denominator. We currently don't have a great way to override that in headers you don't control.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">(Heck, on non-Apple platforms we don't have a great way to do it in headers you do control; Swift is currently keying off the macro names.)<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Jordan<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><blockquote type="cite" class=""><div class="">On Jan 10, 2016, at 13:25 , Austin Zheng via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">I spoke too soon, the cases are also defined as values of that type. So, a working version of your code:</span></span><br class=""></div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" class="">&nbsp;</div>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" class=""><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(112, 61, 170);" class=""><span class="colour" style="color:rgb(187, 44, 162)">extension</span><span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(79, 129, 135)">fe_type</span><span style="" class=""><span class=""></span>:<span class=""></span></span>CustomStringConvertible<span style="" class=""><span class=""></span>{</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;" class=""><span class=""></span><span class="colour" style="color:rgb(187, 44, 162)">public</span><span class=""></span><span class="colour" style="color:rgb(187, 44, 162)">var</span><span class=""></span>description:<span class=""></span><span class="colour" style="color:rgb(112, 61, 170)">String</span><span class=""></span>{<br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(187, 44, 162);" class=""><span style="" class=""><span class=""></span></span>switch<span style="" class=""><span class=""></span></span>self<span style="" class=""><span class=""></span>{</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(187, 44, 162);" class=""><span style="" class=""><span class=""></span></span>case<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_QPSK</span><span style="" class="">:<span class=""></span></span>return<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(209, 47, 27)">"QPSK"</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(187, 44, 162);" class=""><span style="" class=""><span class=""></span></span>case<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_QAM</span><span style="" class="">:<span class=""></span></span>return<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(209, 47, 27)">"QAM"</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(187, 44, 162);" class=""><span style="" class=""><span class=""></span></span>case<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_OFDM</span><span style="" class="">:<span class=""></span></span>return<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(209, 47, 27)">"OFDM"</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(187, 44, 162);" class=""><span style="" class=""><span class=""></span></span>case<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_ATSC</span><span style="" class="">:<span class=""></span></span>return<span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(209, 47, 27)">"ATSC"</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;color:rgb(209, 47, 27);" class=""><span style="" class=""><span class=""></span></span><span class="colour" style="color:rgb(187, 44, 162)">default</span><span style="" class="">:<span class=""></span></span><span class="colour" style="color:rgb(61, 29, 129)">fatalError</span><span style="" class="">(</span>"can't be exhaustive"<span style="" class="">)</span><br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;" class="">&nbsp; &nbsp; }<br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;" class="">&nbsp; }<br class=""></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;" class="">}<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Best,<br class=""></div>
<div class="">Austin<br class=""></div>
<div class=""><div class="">&nbsp;</div>
<div class=""><blockquote type="cite" class=""><div class="">On Jan 10, 2016, at 1:22 PM, Austin Zheng &lt;<a href="mailto:austinzheng@gmail.com" class="">austinzheng@gmail.com</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div style="word-wrap:break-word;-webkit-line-break:after-white-space;" class=""><div class="">Hi Ryan,<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Apologies, I should have been more clear. In Xcode you can alt(?)-click on a type (e.g the 'MyType' in "let a : MyType = 123") in the IDE to pop up a little window that shows you the definition, including the type and some other information. If you're on a Linux box or not using an IDE you probably don't have that option.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">The only methods I see exposed on the Swift imported type are initializers taking a integer raw value, and a 'rawValue' property for getting back out the raw value. Hope that helps.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">Austin<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><blockquote type="cite" class=""><div class="">On Jan 10, 2016, at 1:18 PM, Ryan Lovelett &lt;<a href="mailto:swift-dev@ryan.lovelett.me" class="">swift-dev@ryan.lovelett.me</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div class=""><div class="">Austin,<br class=""></div>
<div class="">&nbsp;</div>
<div class="">I guess I should say that the `typedef` is coming from a<span class=""></span><a href="http://lxr.free-electrons.com/source/include/linux/dvb/frontend.h?v=3.2" class="">Linux kernel header</a>. So I don't think I'm going to be able to add any macros to the definition.<br class=""></div>
<div class="">&nbsp;</div>
<div class="">What do you mean about alt-click? Alt click where?<br class=""></div>
<div class="">&nbsp;</div>
<div class="">On Sun, Jan 10, 2016, at 04:12 PM, Austin Zheng wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">fe_type is being imported as a struct (alt-click 'fe_type' in Swift). I think if you want it to be imported as an enum you need to use the NS_ENUM macro in the definition, which might not be possible in your case.<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div class="">Austin<br class=""></div>
<div class=""><div class="">&nbsp;</div>
<div class=""><blockquote type="cite" class=""><div class="">On Jan 10, 2016, at 1:06 PM, Ryan Lovelett via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""></div>
<div class="">&nbsp;</div>
<div class=""><div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">typedef enum fe_type {</span></span><br class=""></div>
<div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">&nbsp;FE_QPSK,</span></span><br class=""></div>
<div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">&nbsp;FE_QAM,</span></span><br class=""></div>
<div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">&nbsp;FE_OFDM,</span></span><br class=""></div>
<div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">&nbsp;FE_ATSC</span></span><br class=""></div>
<div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">} fe_type_t;</span></span><br class=""></div>
</div>
</blockquote></div>
</div>
</div>
</blockquote><div class="">&nbsp;</div>
</div>
</div>
</blockquote></div>
<div class="">&nbsp;</div>
</div>
</div>
</blockquote></div>
<div class="">&nbsp;</div>
</div>
</div>
<div class=""><img style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-right:0px !important;margin-bottom:0px !important;margin-left:0px !important;padding-top:0px !important;padding-right:0px !important;padding-bottom:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/ec25267e80a29f1621798f1f0d4383f5ad930b5d75c79286b50471103399033c/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3a554a743178495e6858605273326240557d2236487054347e433846675b4c4d2236447a40717b6150376b6f4653514a50335f4d4964553744596470715352447f485871676f4832326d473d653e6a795c4c6b6a44433a6c436076447b467b41657d4548653342357831785737655a7a5034434678615c41476d223246417558607265365d66394d697739607b60516f62776657314471763d22364441337d22324163444b6d22324544734b61603a5467674476344f457d2232437e6d2236454a583a41465177683546314f695732357a633469683d626251345277664d66627861326237325d494743495173585d6657336650536967696f4e694d23344/open" class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"><span class=""></span></span></span><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">_______________________________________________</span></span><br class=""></div>
<div class=""><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">swift-dev mailing list</span></span><br class=""></div>
<div class=""><a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class=""></div>
<div class=""><a style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;orphans:auto;text-align:start;text-indent:0px;text-transform:none;white-space:normal;widows:auto;word-spacing:0px;-webkit-text-stroke-width:0px;" href="https://lists.swift.org/mailman/listinfo/swift-dev" class="">https://lists.swift.org/mailman/listinfo/swift-dev</a><br class=""></div>
</div>
</blockquote></div>
</blockquote><div class="">&nbsp;</div>
</div>

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