<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><blockquote type="cite" class="">On Nov 4, 2017, at 9:38 AM, Dennis Weissmann via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><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="">In a project (iOS 11 only) we use Touch ID for authentication and handle errors like so:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""><span style="color: #ba2da2" class="">private</span> <span style="color: #ba2da2" class="">func</span> handleLocalAuthenticationError(<span style="color: #ba2da2" class="">_</span> error: <span style="color: #703daa" class="">LAError</span>) {</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""> <span style="color: #ba2da2" class="">switch</span> error.<span style="color: #703daa" class="">code</span> {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>userCancel<span style="" class="">, .</span>appCancel<span style="" class="">, .</span>systemCancel<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle cancelation</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>authenticationFailed<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle failure</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>passcodeNotSet<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle passcode absence</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>touchIDNotEnrolled<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle no Touch ID enrollment</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>touchIDNotAvailable<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle no Touch ID availabe</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>touchIDLockout<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle Touch ID Lockout</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>userFallback<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle user fallback</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>invalidContext<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle failure with invalid context</div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(62, 30, 129);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>notInteractive<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="" class=""> </span>// Handle no interaction allowed error</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class=""> }</div><div style="margin: 0px; font-stretch: normal; line-height: normal;" class="">}</div><div class=""><br class=""></div></div></div></div><div class="">This worked fine until recently, when with the release of iOS 11 and the introduction of Face ID, `.touchIDLockout`, `.touchIDNotEnrolled` and `.touchIDNotAvailable` were deprecated in favor of the newly introduced `.biometryLockout`, `.biometryNotEnrolled` and `.biometryNotAvailable`.</div><div class=""><br class=""></div><div class="">When we link against the latest SDK we need to add those in order to compile (which is obviously good).</div><div class=""><br class=""></div><div class="">Now when we add those cases, the compiler shows the following warnings:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px 0px 0px 12px; text-indent: -12px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><unknown>:0: warning: 'touchIDLockout' was deprecated in iOS 11.0: use LAErrorBiometryLockout</div><div style="margin: 0px 0px 0px 12px; text-indent: -12px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><unknown>:0: warning: 'touchIDNotEnrolled' was deprecated in iOS 11.0: use LAErrorBiometryNotEnrolled</div><div style="margin: 0px 0px 0px 12px; text-indent: -12px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><unknown>:0: warning: 'touchIDNotAvailable' was deprecated in iOS 11.0: use LAErrorBiometryNotAvailable</div></div><div class=""><br class=""></div><div class="">The problem here is, that we can't remove the old ones and replace them with their new variants because for Swift the enum is then not exhaustive (which also makes sense, they're only deprecated, not removed after all).</div><div class=""><br class=""></div><div class="">Even though not optimal (read "really bad because not exhaustive") I thought about removing the old cases and adding a default label:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="color: #ba2da2" class="">private</span> <span style="color: #ba2da2" class="">func</span> handleLocalAuthenticationError(<span style="color: #ba2da2" class="">_</span> error: <span style="color: #703daa" class="">LAError</span>) {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">switch</span> error.<span style="color: #703daa" class="">code</span> {</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>userCancel<span style="" class="">, .</span>appCancel<span style="" class="">, .</span>systemCancel<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle cancelation</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>authenticationFailed<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle failure</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>passcodeNotSet<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle passcode absence</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>biometryNotEnrolled<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle no biometry enrollment</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>biometryNotAvailable<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle no biometry availabe</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>biometryLockout<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle biometry Lockout</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>userFallback<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle user fallback</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>invalidContext<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle failure with invalid context</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span><span style="text-decoration: underline ; color: #ba2da2" class="">c</span><span style="color: #ba2da2" class="">ase</span><span style="" class=""> .</span>notInteractive<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// Handle no interaction allowed error</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>default<span style="" class="">:</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);" class=""><span style="" class=""> </span>// hopefully only deprecated cases</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> <span style="color: #ba2da2" class="">break</span></div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""> }</div><div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);" class=""><span style="text-decoration: underline" class="">}</span></div></div><div class=""><br class=""></div><div class="">However, in this case the compiler warns that "Default will never be executed".</div><div class=""><br class=""></div><div class="">Is there any way of getting rid of these warnings (preferably the first 3 so that we don't have to have default clause)?</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">- Dennis </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=""><a href="https://lists.swift.org/mailman/listinfo/swift-users" class="">https://lists.swift.org/mailman/listinfo/swift-users</a><br class=""></div></blockquote><br class=""></div><div>Hi Dennis,</div><div><br class=""></div><div>.touchIDLockout, .touchIDNotAvailable, and .touchIDNotEnrolled have the same rawValue as .biometryLockout, .biometryNotAvailable, and .biometryNotEnrolled. So if you handle the latter, it’ll also handle the former.</div><div><br class=""></div><div>Charles</div><br class=""></body></html>