What's wrong with comparing non-optional bool in a single if structure in swift
<p>I have been coding in Swift for a while, and I think I had to put a ! on all my let field variables that were not defined immediately.</p>

<p>Now I notice today that this piece of code does not compile and I am really surprised? why is this?</p>

<pre><code>class MyClass : Mapper {
    var a: Bool!

    required init?(_ map: Map) {
    }

    // Mappable
    func mapping(map: Map) {
        a   &lt;- map["a"]
    }
}

let myClass = MyClass()

if myClass.a { // Compiler not happy
    //  Optional type 'Bool!' cannot be used as a boolean; test for '!= nil' instead
}

if true &amp;&amp; myClass.a { // Compiler happy

}

if myClass.a &amp;&amp; myClass.a { // Compiler happy

}
</code></pre>

<p>Apple Swift version 2.2</p>

<p><strong>Edit</strong><br>
Some people point out why am I using a <code>let</code> for a variable that will never change. I mentioned it is for field variables but I shorten the example. When using ObjectMapper (<a href="http://github.com/Hearst-DD/ObjectMapper" rel="nofollow">http://github.com/Hearst-DD/ObjectMapper</a>), all the fields are not defined immediately in the init. This is why they are all either optional? or required!</p>