title: Swift: Trying to encode user and pass into UTF8
body: <p>I am using an API that does not take headers to validate user credentials in a log in screen. I want to encode the email and pass into UTF8 in case there are characters such as a "+" in an email or pass. Here is my code:</p>
  
  <pre><code>func logIn() {
  
  
      var email = emailTextField.text
      var pass = passwordTextField.text
  
      var encodedEmail = email.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet())
      var encodedPass = pass.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLHostAllowedCharacterSet())
  
      var url = "https://www.photoshelter.com/psapi/v3/mem/authenticate?api_key=\(api_key)&amp;email=\(encodedEmail!)&amp;password=\(encodedPass!)&amp;mode=token"
  
  
      var baseURL:NSURL? = NSURL(string: url)
      var request: NSMutableURLRequest? = NSMutableURLRequest(URL: baseURL!)
      var session = NSURLSession.sharedSession()
      var task = session.dataTaskWithRequest(request!, completionHandler: { (data, response, error) -&gt; Void in
          dispatch_async(dispatch_get_main_queue(), { () -&gt; Void in
  
  
              if response == nil {
                  UIAlertView(title: "PhotoShelter", message: "No internet connection", delegate: nil, cancelButtonTitle: "Cancel").show()
              } else {
                  var responseObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil)
                  var status: AnyObject? = responseObject?.objectForKey("status")
  
                  if status as String != "ok" {
                      UIAlertView(title: "PhotoShelter", message: "Invalid Credentials", delegate: nil, cancelButtonTitle: "OK").show()
                  } else {
  
                      var tokenString: AnyObject? = responseObject?.objectForKey("data")
                      var token: AnyObject? = tokenString?.objectForKey("token")
                      println(token!)
  
  
                  }
  
              }
  
          })
      })
      task.resume()
  }
  </code></pre>
  
  <p>It runs fine, and I get the token printed no issues with a regular log in. When I add an email with a "+" the baseURL does not read it. It converts the "@" sign into %40 but ignores the "+". </p>
  
  <p>I would also like to note that when I used:</p>
  
  <pre><code>var encodedEmail = email.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
  var encodedPass = pass.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
  </code></pre>
  
  <p>It did not work either. Any ideas on how to fix this? </p>