<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I found a related bug here:&nbsp;<a href="https://bugs.swift.org/browse/SR-6204" class="">https://bugs.swift.org/browse/SR-6204</a><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Dec 5, 2017, at 10:10 AM, Dennis Weissmann via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi swift-users,<div class=""><br class=""></div><div class="">I have found another weird behavior (IMO) and wanted to ask for the right way to handle this:</div><div class=""><br class=""></div><div class="">Imagine I want to switch over a Swift string which contains a UTI to map that UTI to an enum.</div><div class=""><br class=""></div><div class="">(A playground is attached for you to easily reproduce, this is tested with Xcode 9.1's included toolchain, also happens in projects)</div><div class=""><br class=""></div><div class="">I would expect the following to work:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">import</span> MobileCoreServices</div></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">enum</span> MimeType {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">case</span> text</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">case</span> unknown</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">public</span> <span style="color: #c42275" class="">init</span>(uti: <span style="color: #703daa" class="">String</span>) {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; color: rgb(19, 55, 255); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #1e9421" class="">// Source: </span><a href="https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html" class="">https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html</a></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">switch</span> uti.<span style="color: #3e1e81" class="">lowercased</span>() {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #c42275" class="">case</span><span style="" class=""> </span>kUTTypeText<span style="" class=""> </span><span style="color: #c42275" class="">as</span><span style="" class=""> </span>String<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">self</span> = .<span style="color: #31595d" class="">text</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">default</span>:</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">self</span> = .<span style="color: #31595d" class="">unknown</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">The error I get here is</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">warning: UTITest.playground:8:26: warning: 'as' test is always true</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; case kUTTypeText as String:</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""></b></span><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">error: UTITest.playground:8:14: error: expression pattern of type 'CFString' cannot match values of type 'String'</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; case kUTTypeText as String:</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^~~~~~~~~~~</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;^~~~~~~~~~~</b></div></div><div class="">The only way I found to resolve this is to also import Foundation (which makes sense but is not really obvious).</div><div class=""><br class=""></div><div class="">Alright, that gives me this:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">import</span> MobileCoreServices</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">import</span> Foundation</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">enum</span> MimeType {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">case</span> text</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">case</span> unknown</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">public</span> <span style="color: #c42275" class="">init</span>(uti: <span style="color: #703daa" class="">String</span>) {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; color: rgb(19, 55, 255); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #1e9421" class="">// Source: </span><a href="https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html" class="">https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html</a></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">switch</span> uti.<span style="color: #3e1e81" class="">lowercased</span>() {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #c42275" class="">case</span><span style="" class=""> </span>kUTTypeText<span style="" class=""> </span><span style="color: #c42275" class="">as</span><span style="" class=""> </span>String<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">self</span> = .<span style="color: #31595d" class="">text</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">default</span>:</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">self</span> = .<span style="color: #31595d" class="">unknown</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">warning: UTITest.playground:8:26: warning: 'as' test is always true</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; case kUTTypeText as String:</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; min-height: 14px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class=""></b></span><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">error: UTITest.playground:8:14: error: 'CFString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp; &nbsp; &nbsp; &nbsp; case kUTTypeText as String:</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</b></span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; as String</b></span></div></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Uhm, okay? So let's do that:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class=""><span style="color: #c42275" class="">enum</span> MimeType {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">case</span> text</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">case</span> unknown</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; <span style="color: #c42275" class="">public</span> <span style="color: #c42275" class="">init</span>(uti: <span style="color: #703daa" class="">String</span>) {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; color: rgb(19, 55, 255); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #1e9421" class="">// Source: </span><a href="https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html" class="">https://developer.apple.com/library/content/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html</a></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">switch</span> uti.<span style="color: #3e1e81" class="">lowercased</span>() {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; color: rgb(112, 61, 170); background-color: rgb(255, 255, 255);" class=""><span style="" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #c42275" class="">case</span><span style="" class=""> </span>kUTTypeText<span style="" class=""> </span><span style="color: #c42275" class="">as</span><span style="" class=""> </span>String<span style="" class=""> </span><span style="color: #c42275" class="">as</span><span style="" class=""> </span>String<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">self</span> = .<span style="color: #31595d" class="">text</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">default</span>:</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c42275" class="">self</span> = .<span style="color: #31595d" class="">unknown</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; background-color: rgb(255, 255, 255); min-height: 14px;" class=""><br class=""></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: &quot;Fira Code&quot;; background-color: rgb(255, 255, 255);" class="">}</div></div><div class=""><br class=""></div><div class="">As weird as it looks, it works ... My question is: Is this behavior intended?</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">- Dennis</div><div class=""></div></div><span id="cid:D8493669-11D5-489A-9216-26CAFD367723@dhcp.wdf.sap.corp">&lt;UTITest.playground&gt;</span><meta http-equiv="Content-Type" content="text/html; charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>