I am trying to create a required field in Swift 2. Everytime I run this code I receive no errors, but I never receive an error message with the text field is empty. The segue is always performed. Any idea what I am doing wrong?
Thanks!
@IBOutlet weak var userName: UITextField!
@IBAction func userConfermation(sender: AnyObject) {
if userName.text!.isEmpty {
let alertController = UIAlertController(title: "Error",
message: "Incorrect Password", preferredStyle:UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "Dismiss",
style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
} else {
performSegueWithIdentifier("final", sender: self)
}
return
}