This a little confusing, I don't think adding yet another question mark helps. <span></span>The ?? (<font size="2"><span style="background-color:rgba(255,255,255,0)"> nil coalescing operator</span></font>) already included in swift handles checking for nil values. If anything, the ternary operator just makes matters worse in this example. If else would be better imo. <div><br><div><a href="https://lists.swift.org/pipermail/swift-evolution/2015-December/000133.html">https://lists.swift.org/pipermail/swift-evolution/2015-December/000133.html</a><br></div><div><br><br>On Friday, December 4, 2015, Amir Michail <<a href="mailto:a.michail@me.com">a.michail@me.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So for example the following (probable) bug would result in a compile error:<br>
<br>
let f = x < 5 // where x is optional and could be nil<br>
<br>
If that was really what was intended, you would need to write:<br>
<br>
let f = x? < 5<br>
<br>
Similarly, the rule would also apply for functions that return an optional type:<br>
<br>
let f = x()? < 5<br>
<br>
A major advantage of this approach is it would encourage programmers to unwrap optionals early to avoid writing “?” and “?!" frequently in their code.<br>
<br>
Note that conditional chaining would just make use of the existing “?” suffix. There is no need to add another “?” after that.<br>
<br>
let f = x?.g?.h<br>
let f = x()?.g?.h<br>
<br>
As for implicitly unwrapped optionals, a “?” suffix would only be used when you want to treat a value as an optional (e.g., when comparing it to nil). For example, for x of type Int?, one could write:<br>
<br>
let y = (x? == nil) ? 0 : x<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'swift-evolution@swift.org')">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>