title: Swift: testing against optional value in switch case
body: <p>In Swift, how can I write a case in a switch statement that tests the value being switched against the contents of an <em>optional</em>, skipping over the case if the optional contains <code>nil</code>?</p>
  
  <p>Here's how I imagine this might look:</p>
  
  <pre><code>let someValue = 5
  let someOptional: Int? = nil
  
  switch someValue {
  case someOptional:
      // someOptional is non-nil, and someValue equals the unwrapped contents of someOptional
  default:
      // either, someOptional is nil, or someOptional is non-nil but someValue does not equal the unwrapped contents of someOptional
  }
  </code></pre>
  
  <p>If I just write it exactly like this, the compiler complains that <code>someOptional</code> is not unwrapped, but if I explicitly unwrap it by adding <code>!</code> to the end, I of course get a runtime error any time <code>someOptional</code> contains <code>nil</code>. Adding <code>?</code> instead of <code>!</code> would make some sense to me (in the spirit of optional chaining, I suppose), but doesn't make the compiler error go away (i.e. doesn't actually unwrap the optional).</p>