title: Swift optional parameter functions
body: <p>So I have the following function:</p>
  
  <pre><code>func remoteCall(_url:String, _params:[String: String]?=nil){
     ...
  
  
     ...
     Alamofire.request(.POST, _url, parameters: _params)   //requires _params to be of type [String String!]
  
     ...
  }
  </code></pre>
  
  <p>As you can see, I can do:</p>
  
  <pre><code>let url = "https://eamorr.com/remote.php"
  remoteCall(url)    //works great!
  </code></pre>
  
  <p>Or, I can do:</p>
  
  <pre><code>let url = "https://eamorr.com/remote.php"
  let params = [
      "email": "eamorr@eamorr.com",
      "pword": "secret"
  ]
  remoteCall(url, _params:params)   //works great!
  </code></pre>
  
  <p>However, what I can't do is:</p>
  
  <pre><code>let url = "https://eamorr.com/remote.php"
  let params = [
      "email": email.text,   //where "email" is a UITextField
      "pword": pword.text    //where "pword" is a UITextField
  ]
  remoteCall(url, _params:params)   //this doesn't work
  </code></pre>
  
  <p>I get this error:</p>
  
  <p><code>'String!' is not identical to 'String'</code></p>
  
  <p><strong>I need to be able to accomodate all three situations (pass nothing, pass raw strings, and pass UITextField values)</strong></p>
  
  <p>Unfortunately, if I try to change the function signature (note the '!' after the keyword "String") to:</p>
  
  <pre><code>func remoteCall(_url:String, _params:[String: String!]?=nil){
     ...
  
     ...
  }
  </code></pre>
  
  <p>The UITextField values work, passing nil works, but the raw strings situation fails at run-time.</p>
  
  <p><code>fatal error: can't unsafeBitCast between types of different sizes</code></p>
  
  <p><code>EXC_BAD_INSTRUCTION</code></p>
  
  <p>I'll be using this function a lot, so I would like not to have to wrap my "params" variable up in messy code.</p>
  
  <p>I'm new to Swift, an Objective-C head, and trying to re-learn everything again...</p>
  
  <p>I guess if I can somehow convert any incorrect <code>[String: String]</code> to <code>[String: String!]</code> neatly inside the function without disturbing any <code>nil</code>'s or <code>[String: String!]</code>'s that already work?</p>