[swift-evolution] Please remove obscure "!" requirements for implicitly unwrapped optionals

Chris Lattner clattner at apple.com
Fri Dec 4 18:04:33 CST 2015


> On Dec 4, 2015, at 1:18 PM, Per Melin <p at greendale.se> wrote:
> 
> On Fri, Dec 4, 2015 at 1:03 AM, Amir Michail <a.michail at me.com <mailto:a.michail at me.com>> wrote:
> 
> I really don’t like having to put the ! suffix in boolean contexts:
> 
> To be explicit:
> 
>     let a: Bool! = false
> 
>     if a == false { }  // Works as expected
> 
>     if !a { }  // Works as expected
> 
>     if a { }   // "error: optional type 'Bool!' cannot be used as a boolean; test for '!= nil' instead"
> 
> Xcode "fixes" the last line like this:
> 
>     if (a != nil) { }

Huh ok.  Out of curiosity, why are you using IUOs for this?  I’m interested in (continuing to ) dramatically reduce the prevalence of IOUs in code (eliminating the need to use them), and reduce their power in various ways.  IUOs are one of the biggest sources of surprising behavior in Swift, and while they were a necessary feature to start with, their importance is going down over time.

-Chris

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151204/74ac8e53/attachment-0001.html>


More information about the swift-evolution mailing list