title: What's the difference between if nil != optional … and if let _ = optional …
body: <p>I need to test if an expression which returns an optional is <code>nil</code>. This seems like a no-brainer, but here is the code.</p>
  
  <pre><code>if nil != self?.checklists.itemPassingTest({ $0 === note.object }) {
      …
  }
  </code></pre>
  
  <p>Which, for some reason, looks unpleasant to my eye.</p>
  
  <pre><code>if let item = self?.checklists.itemPassingTest({ $0 === note.object }) {
      …
  }
  </code></pre>
  
  <p>Looks much better to me, but I don't actually need the item, I just need to know if one was returned. So, I used the following.</p>
  
  <pre><code>if let _ = self?.checklists.itemPassingTest({ $0 === note.object }) {
      …
  }
  </code></pre>
  
  <p>Am I missing something subtle here? I think <code>if nil != optional …</code> and <code>if let _ = optional …</code> are equivalent here.</p>
  
  <hr>
  
  <p><strong>Update to address some concerns in the answers</strong></p>
  
  <ol>
  <li><p>I don't see the difference between <code>nil != var</code> and <code>var != nil</code>, although I generally use <code>var != nil</code>. In this case, pushing the <code>!= nil</code> after the block gets the boolean compare of block mixed in with the boolean compare of the if.</p></li>
  <li><p>The use of the <a href="https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Patterns.html#//apple_ref/swift/grammar/wildcard-pattern">Wildcard Pattern</a> should not be all that surprising or uncommon. They are used in tuples <code>(x, _) = (10, 20)</code>, for-in loops <code>for _ in 1...5</code>, case statements <code>case (_, 0):</code>, and more (NOTE: these examples were taken from The Swift Programming Language).</p></li>
  </ol>
  
  <p>This question is about the functional equivalency of the two forms, not about coding style choices. That conversation can be had on programmers.stackexchange.com.</p>
  
  <hr>
  
  <p>After all this time, Swift 2.0 makes it moot</p>
  
  <pre><code>if self?.checklists.contains({ $0 === note.object }) ?? false {
      …
  }
  </code></pre>