title: Using the Swift if let with logical AND operator &&
body: <p>We know that we can use an <code>if let</code> statement as a shorthand to check for an optional nil then unwrap.</p>
  
  <p>However, I want to combine that with another expression using the logical AND operator <code>&amp;&amp;</code>.</p>
  
  <p>So, for example, here I do optional chaining to unwrap and optionally downcast my rootViewController to tabBarController. But rather than have nested if statements, I'd like to combine them.</p>
  
  <pre><code>if let tabBarController = window!.rootViewController as? UITabBarController {
      if tabBarController.viewControllers.count &gt; 0 {
          println("do stuff")
       }
   }
  </code></pre>
  
  <p>Combined giving:</p>
  
  <pre><code>if let tabBarController = window!.rootViewController as? UITabBarController &amp;&amp;
      tabBarController.viewControllers.count &gt; 0 {
          println("do stuff")
       }
  }
  </code></pre>
  
  <p>The above gives the compilation error <strong>Use of unresolved identifier 'tabBarController'</strong></p>
  
  <p>Simplifying:</p>
  
  <pre><code>if let tabBarController = window!.rootViewController as? UITabBarController &amp;&amp; true {
     println("do stuff")
  }
  </code></pre>
  
  <p>This gives a compilation error <strong>Bound value in a conditional binding must be of Optional type</strong>. Having attempted various syntactic variations, each gives a different compiler error. I've yet to find the winning combination of order and parentheses.</p>
  
  <p><strong>So, the question is, is it possible and if so what is correct syntax?</strong></p>
  
  <p><em>Note that I want to do this with an <code>if</code> statement <strong>not</strong> a <code>switch</code> statement or a ternary <code>?</code> operator.</em></p>