<div dir="ltr"><div class="gmail_default" style="font-family:georgia,serif">I encountered similar issue today too.</div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default" style="font-family:georgia,serif">My code was like </div><div class="gmail_default" style="font-family:georgia,serif"><br></div><div class="gmail_default"><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">if</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">try</span><span style="font-variant-ligatures:no-common-ligatures">? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">bookmarkPlistURL</span><span style="font-variant-ligatures:no-common-ligatures">.checkResourceIsReachable() ?? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">false</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></p><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"> ....</span></p><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p><p style="font-family:menlo;margin:0px;font-size:11px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><br></span></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="georgia, serif">And the IDE (Xcode) wrongly suggests me to change try? to try!, which I did and my app crashed when `throws`. The only right approach is to change code to </font></span></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="georgia, serif"><br></font></span></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"></span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(62,30,129)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">if</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">try</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">bookmarkPlistURL</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures">checkResourceIsReachable</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">()) ?? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">false</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> {</span></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><span style="font-variant-ligatures:no-common-ligatures"><font face="georgia, serif"><br></font></span></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><font face="georgia, serif">Besides, if you chose to use an indicator, Xcode would kindly tell you the `?? false` part would never run.</font></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><font face="georgia, serif"><br></font></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> foo = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">try</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)">bookmarkPlistURL</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(62,30,129)">checkResourceIsReachable</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">() ?? </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">false</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span style="font-variant-ligatures:no-common-ligatures">// Left side of nil coalescing operator '??' has non-optional type 'Bool', so the right side is never used</span></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><font face="georgia, serif"><br></font></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><font face="georgia, serif">So the behavior is on purpose? I just want to learn if anyone can tell me why?</font></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><font face="georgia, serif"><br></font></p><p style="margin:0px;line-height:normal;color:rgb(0,0,0)"><font face="georgia, serif">Zhaoxin</font></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 4, 2016 at 10:38 PM, J.E. Schotsman via swift-users <span dir="ltr"><<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I was surprised when I got a compiler error for this code:<br>
<br>
if try? MyThrowingFunction() != nil {…} (MyThrowingFunction does not return an optional value)<br>
<br>
This compiles:<br>
<br>
if (try? MyThrowingFunction) != nil {…} (Xcode 7.3.1)<br>
<br>
Shouldn’t try? have higher priority than != here?<br>
<br>
Please disregard if this is changed in Swift 3<br>
<br>
Jan E.<br>
______________________________<wbr>_________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-users</a><br>
</blockquote></div><br></div>