ios - how to check textfield validation in swift when button performs dismiss segue? -


this question has answer here:

i try perform segue & text field validation on action of button. performs dismiss segue without validation. new ios & swift.

create global bool variable

var pass=true; 

in button action

@ibaction func button_action(sender: anyobject) {      if txt_out.text==""   //txt_out uitextfield outlet     {         pass=false;     }     else     {         pass=true;     } } override func shouldperformseguewithidentifier(identifier: string, sender: anyobject?) -> bool {     return pass; } 

or can directly put validation of uitextfield in shouldperformseguewithidentifier method:

override func shouldperformseguewithidentifier(identifier: string, sender: anyobject?) -> bool {     if txt_out.text==""     {         return false;     }     else     {         return true;     }  } 

Comments