title: Swift - Take Nil as Argument in Generic Function with Optional Argument
body: <p>I am trying to create a generic function that can take an optional argument.
  Here's what I have so far:</p>
  
  <pre><code>func somethingGeneric&lt;T&gt;(input: T?) {
      if (input != nil) {
          print(input!);
      }
  }
  
  somethingGeneric("Hello, World!") // Hello, World!
  somethingGeneric(nil) // Errors!
  </code></pre>
  
  <p>It works with a <code>String</code> as shown, but not with <code>nil</code>.
  Using it with <code>nil</code> gives the following two errors:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: cannot invoke 'somethingGeneric' with an argument list of type '(_?)'
  note: expected an argument list of type '(T?)'
  </code></pre>
  
  <p>What am I doing wrong and how should I correctly declare/use this function? Also, I want to keep the usage of the function as simple as possible (I don't want do something like <code>nil as String?</code>).</p>