title: Get rid of these Optional values
body: <p><em>Using Xcode 7 beta, Swift 2.0</em></p>
  
  <p>I'm saving and loading credentials to keychain, somehow when loading I get "Optional(value)" back, it looks like this is really part of the string as it also displayed like so in a textbox or when sending to API</p>
  
  <p>This is how I save and load credentials now, as you see I've done a lot of extra nil checking to make sure it is not nil or Optional, it is indeed a overuse of explanation marks...</p>
  
  <pre><code>func SaveCredentials(credentials : [String : String!]!) -&gt; Bool
  {
      if(credentials.count == 2)
      {
          //only proceed when we have two keys:  username and password
          let username = credentials["username"]
          let password = credentials["password"]
  
          if let usernameStr = username
          {//also tried username!=nil &amp;&amp; password != nil
              if let passwordStr = password
              { //usernameStr and passwordStr is of type String!
                  let NsDataUsername = usernameStr!.dataUsingEncoding(NSUTF8StringEncoding)
                  let NsDataPassword = passwordStr!.dataUsingEncoding(NSUTF8StringEncoding)
                  if(NsDataUsername != nil &amp;&amp; NsDataPassword != nil)
                  {
                      LocalStorage.saveToKeyChain("username", data: NsDataUsername!)
                      LocalStorage.saveToKeyChain("password", data: NsDataPassword!)
                      return true
                  }
              }
  
          }
      }
      return false
  }
  
  func LoadCredentials() -&gt; [String : String!]?
  {
      let NsDataUsername = LocalStorage.loadFromKeyChain("username")
      let NsDataPassword = LocalStorage.loadFromKeyChain("password")
      if(NsDataUsername != nil &amp;&amp; NsDataPassword != nil)
      {
          let username : String! = String(NSString(data: NsDataUsername!, encoding: NSUTF8StringEncoding))
          let password : String! = String(NSString(data: NsDataPassword!, encoding: NSUTF8StringEncoding))
          if let usernameStr = username
          {
              if let passwordStr = password
              { // password is of type String!, passwordStr is of type String
                  var credentials : [String: String!] = [String : String]()
                  credentials["username"] = usernameStr
                  credentials["password"] = passwordStr
                  return credentials
              }
          }
      }
      return nil
  }
  </code></pre>
  
  <p>And when I send to Api, this is my method that also requires a non-optional string. This method does work when logging in, getting strings from text fields, but does not filter out that Optional when coming from keychain.</p>
  
  <pre><code>func LoginUser(email : String!, password : String!)
  {
      print("LoginUser(email : \(email), password: \(password))")
      var parameters = [String : AnyObject]()
      parameters["UserName"] = email
      parameters["Password"] = password
     ......
  </code></pre>
  
  <p>The strings that I send to the SaveCredentials method, are the same that the user logged in with:</p>
  
  <pre><code>func LoginLocalAccount(email : String!, password : String!)
  {
      databaseAPI.LoginUser(email!, password: password!) //login goes just fine
      saveCredentials(email!, password: password!) //manages to get Optional in it..
  }
  </code></pre>
  
  <p>I suspect it has something to do with saving and loading from keychain, for interests, <a href="https://gist.github.com/s-aska/e7ad24175fb7b04f78e7" rel="nofollow">this</a> is what I use to save and load from keychain.</p>
  
  <p>I want to get rid of them because when the app starts, it loads the credentials and tries to login at my API. Ofcourse I get an error back that the username is not a valid e-mail, because it is Optional(email@adress.com)</p>