title: Saving username and password using UISwitch in Swift
body: <p>Ive searched a lot of threads and this is my last resort because Ive seen this question asked different ways but not exactly for swift and for Username and password saving. I want my UISwitch when turned on to save my username and password info. I've been trying all day to get this UISwitch to save my username and password using NSUserDefaults. Please help me I'm at my whits end with trying it, I've searched almost every forum to find the answer but not many people show you exactly how to implement it. Below is my code. I know its bleak, as I am a beginner, but I have my "Login Button" saving my username and password, but i don't know how to get it to only save that information when I click the UISwitch and how to save it in the "view did load method".  thanks for the help in advance!! I don't know what code to include into my UISwitch Method.
  Here is the first part of my login button and then my view did load method. I don't have any code for the UISwitchMethod</p>
  
  <pre><code> override func viewDidLoad() {
  super.viewDidLoad()
  
  //Save username and password info if Save UISwitch is selected
  
    switchState.on = NSUserDefaults.standardUserDefaults().boolForKey("switchState")
  NSUserDefaults.standardUserDefaults().boolForKey("keepUsername")
  NSUserDefaults.standardUserDefaults().boolForKey("keepPassword")
  
  }
  
  @IBAction func LoginButton(sender: AnyObject) {
  
  var username = self.usernameTextField.text
  var password = self.passwordTextField.text
  var user = PFUser.currentUser()
  
  
  NSUserDefaults.standardUserDefaults().setObject(username, forKey: "keepUsername")
  NSUserDefaults.standardUserDefaults().setObject(password, forKey: "keepPassword")
  
  if count(username) &lt; 4 || count(password) &lt; 5 {
  
    var alert: UIAlertView = UIAlertView(title: "Sorry!", message: "Username Must be greater than 4 characters and the password greater that 5 characters", delegate: self, cancelButtonTitle: "Ok")
  
    alert.show()    
  }else { 
    self.actInd.startAnimating()
    PFUser.logInWithUsernameInBackground(username, password: password, block: { (user, NSError) -&gt; Void in
  
      self.actInd.stopAnimating()
  
      if ((user) != nil) {
  
        println("Success \(user) logged in")
  
      self.performSegueWithIdentifier("toHomeFromLogin", sender: self)
  
      }else {
         var alert: UIAlertView = UIAlertView(title: "error", message: "Please Sign up :)", delegate: self, cancelButtonTitle: "Ok")
        alert.show()
      }
  
  
   @IBAction func switchStateChanged(sender: UISwitch) {
  
  
  NSUserDefaults.standardUserDefaults().setBool(switchState.on, forKey: "switchState")
  
    }
  </code></pre>