<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body><div>Jordan,<br></div>
<div> </div>
<div>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="color:rgb(0, 0, 0)"><span class="font" style="font-family:Menlo, monospace"><span class="size" style="font-size:12px">NS_ENUM </span></span></span></span>to the header it still wouldn't compile into a true Swift enum (on a non-Apple platform)?<br></div>
<div> </div>
<div>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></div>
<div> </div>
<div>However this <i>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></div>
<div> </div>
<div>On Mon, Jan 11, 2016, at 01:11 PM, Jordan Rose wrote:<br></div>
<blockquote type="cite"><div>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></div>
<div> </div>
<div>(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></div>
<div> </div>
<div>Jordan<br></div>
<div> </div>
<div><blockquote type="cite"><div>On Jan 10, 2016, at 13:25 , Austin Zheng via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:<br></div>
<div> </div>
<div><div><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></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;"> </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;"><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);"><span class="colour" style="color:rgb(187, 44, 162)">extension</span><span style=""><span></span></span><span class="colour" style="color:rgb(79, 129, 135)">fe_type</span><span style=""><span></span>:<span></span></span>CustomStringConvertible<span style=""><span></span>{</span><br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;"><span></span><span class="colour" style="color:rgb(187, 44, 162)">public</span><span></span><span class="colour" style="color:rgb(187, 44, 162)">var</span><span></span>description:<span></span><span class="colour" style="color:rgb(112, 61, 170)">String</span><span></span>{<br></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);"><span style=""><span></span></span>switch<span style=""><span></span></span>self<span style=""><span></span>{</span><br></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);"><span style=""><span></span></span>case<span style=""><span></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_QPSK</span><span style="">:<span></span></span>return<span style=""><span></span></span><span class="colour" style="color:rgb(209, 47, 27)">"QPSK"</span><br></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);"><span style=""><span></span></span>case<span style=""><span></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_QAM</span><span style="">:<span></span></span>return<span style=""><span></span></span><span class="colour" style="color:rgb(209, 47, 27)">"QAM"</span><br></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);"><span style=""><span></span></span>case<span style=""><span></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_OFDM</span><span style="">:<span></span></span>return<span style=""><span></span></span><span class="colour" style="color:rgb(209, 47, 27)">"OFDM"</span><br></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);"><span style=""><span></span></span>case<span style=""><span></span></span><span class="colour" style="color:rgb(79, 129, 135)">FE_ATSC</span><span style="">:<span></span></span>return<span style=""><span></span></span><span class="colour" style="color:rgb(209, 47, 27)">"ATSC"</span><br></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);"><span style=""><span></span></span><span class="colour" style="color:rgb(187, 44, 162)">default</span><span style="">:<span></span></span><span class="colour" style="color:rgb(61, 29, 129)">fatalError</span><span style="">(</span>"can't be exhaustive"<span style="">)</span><br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;"> }<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;"> }<br></div>
<div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;line-height:normal;font-family:Menlo;">}<br></div>
<div> </div>
<div>Best,<br></div>
<div>Austin<br></div>
<div><div> </div>
<div><blockquote type="cite"><div>On Jan 10, 2016, at 1:22 PM, Austin Zheng <<a href="mailto:austinzheng@gmail.com">austinzheng@gmail.com</a>> wrote:<br></div>
<div> </div>
<div><div style="word-wrap:break-word;-webkit-line-break:after-white-space;"><div>Hi Ryan,<br></div>
<div> </div>
<div>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></div>
<div> </div>
<div>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></div>
<div> </div>
<div>Austin<br></div>
<div> </div>
<div><blockquote type="cite"><div>On Jan 10, 2016, at 1:18 PM, Ryan Lovelett <<a href="mailto:swift-dev@ryan.lovelett.me">swift-dev@ryan.lovelett.me</a>> wrote:<br></div>
<div> </div>
<div><div><div>Austin,<br></div>
<div> </div>
<div>I guess I should say that the `typedef` is coming from a<span></span><a href="http://lxr.free-electrons.com/source/include/linux/dvb/frontend.h?v=3.2">Linux kernel header</a>. So I don't think I'm going to be able to add any macros to the definition.<br></div>
<div> </div>
<div>What do you mean about alt-click? Alt click where?<br></div>
<div> </div>
<div>On Sun, Jan 10, 2016, at 04:12 PM, Austin Zheng wrote:<br></div>
<blockquote type="cite"><div>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></div>
<div> </div>
<div><div>Austin<br></div>
<div><div> </div>
<div><blockquote type="cite"><div>On Jan 10, 2016, at 1:06 PM, Ryan Lovelett via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:<br></div>
<div> </div>
<div><div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">typedef enum fe_type {</span></span><br></div>
<div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"> FE_QPSK,</span></span><br></div>
<div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"> FE_QAM,</span></span><br></div>
<div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"> FE_OFDM,</span></span><br></div>
<div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"> FE_ATSC</span></span><br></div>
<div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">} fe_type_t;</span></span><br></div>
</div>
</blockquote></div>
</div>
</div>
</blockquote><div> </div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
</blockquote></div>
<div> </div>
</div>
</div>
<div><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"><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px"><span></span></span></span><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">_______________________________________________</span></span><br></div>
<div><span class="font" style="font-family:Helvetica"><span class="size" style="font-size:12px">swift-dev mailing list</span></span><br></div>
<div><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">swift-dev@swift.org</a><br></div>
<div><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">https://lists.swift.org/mailman/listinfo/swift-dev</a><br></div>
</div>
</blockquote></div>
</blockquote><div> </div>
</body>
</html>