<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 5, 2017, at 9:27 AM, Dennis Weissmann &lt;<a href="mailto:dennis@dennisweissmann.me" class="">dennis@dennisweissmann.me</a>&gt; wrote:<br class=""></blockquote><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Hi Charles,</span><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I do believe you :)</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">The problem is that this doesn't work without a compiler warning if you switch over every case except for the deprecated ones because then the compiler warns that "default will never be executed".</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">As per my first mail feel free to try this out in a playground:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span class="" style="color: rgb(186, 45, 162);">private</span>&nbsp;<span class="" style="color: rgb(186, 45, 162);">func</span>&nbsp;handleLocalAuthenticationError(<span class="" style="color: rgb(186, 45, 162);">_</span>&nbsp;error:&nbsp;<span class="" style="color: rgb(112, 61, 170);">LAError</span>) {</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(186, 45, 162);">switch</span>&nbsp;error.<span class="" style="color: rgb(112, 61, 170);">code</span>&nbsp;{</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>userCancel<span class="" style="">, .</span>appCancel<span class="" style="">, .</span>systemCancel<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle cancelation</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>authenticationFailed<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle failure</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>passcodeNotSet<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle passcode absence</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>biometryNotEnrolled<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle no biometry enrollment</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>biometryNotAvailable<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle no biometry availabe</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>biometryLockout<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle biometry Lockout</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>userFallback<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle user fallback</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>invalidContext<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle failure with invalid context</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(62, 30, 129); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span><span class="" style="text-decoration: underline; color: rgb(186, 45, 162);">c</span><span class="" style="color: rgb(186, 45, 162);">ase</span><span class="" style="">&nbsp;.</span>notInteractive<span class="" style="">:</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// Handle no interaction allowed error</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp;&nbsp;</span>default<span class="" style="">: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(0, 132, 0);">// &lt;- Here the compiler emits a warning that the default will never be executed.</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0); background-color: rgb(255, 255, 255);"><span class="" style="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span>// hopefully only deprecated cases</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(186, 45, 162);">break</span></div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);">&nbsp; &nbsp; }</div><div class="" style="margin: 0px; font-stretch: normal; line-height: normal; font-family: Menlo; background-color: rgb(255, 255, 255);"><span class="" style="text-decoration: underline;">}</span></div></div></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">- Dennis</div></div></blockquote></div><br class=""><div class="">Hi Dennis,</div><div class=""><br class=""></div><div class="">The compiler warning is correct. That default *will* never be executed, because if one of the .touchID cases comes up, control flow will go to the .biometry cases.</div><div class=""><br class=""></div><div class="">Although it’s bridged to Swift, LAError is a C enum, which is just an integer. So if the framework set it to .biometryNotAvailable, it’s -6. If the framework code spelled it .touchIDNotAvailable, it’s still -6. And C has no way to distinguish between the two; -6 is -6. So your .biometryNotAvailable case will catch it either way. You can delete the default case here, and your switch will still be exhaustive (unless Apple adds additional cases to the enum in the future, of course).</div><div class=""><br class=""></div><div class="">Charles</div><div class=""><br class=""></div></body></html>