Skip to main content
2 of 2
edited tags
200_success
  • 144.2k
  • 22
  • 188
  • 473

Checking two text field for match and checking for null

Is this the most efficient way to do this? Any suggestions on some thing I might have missed or can do better?

    func checkPasscodeMatch(){
    println(self.passCodetext1.text)
    println(self.passCodetext2.text)
    // check if pass codes match
    if self.passCodetext1.text == self.passCodetext2.text {
    //check if pass code 1 is blank
        if self.passCodetext1.text == "" {
            let alertView = UIAlertController(title: "ALERT!!", message: "Pass code can not be blank", preferredStyle: UIAlertControllerStyle.Alert)
            alertView.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
            
            self.presentViewController(alertView, animated: true, completion: nil)
        } else {
       defaults.setObject(passCodetext1.text, forKey: "passCode")//store pass code
        dispatch_async(dispatch_get_main_queue()) {
            self.performSegueWithIdentifier("setupTouchID", sender: self)
            }
        }
    } else {
        let alertView = UIAlertController(title: "ALERT!!", message: "Pass Codes do not match", preferredStyle: UIAlertControllerStyle.Alert)
        alertView.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
        
        self.presentViewController(alertView, animated: true, completion: nil)
        passCodetext1.text = ""
        passCodetext2.text = ""
        passCodetext2.resignFirstResponder()
        println("Pass codes do not match.")
    }
}
MwcsMac
  • 275
  • 1
  • 5
  • 10