Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. @IBOutlet weak var userNameTextField: UITextField!
  2. @IBOutlet weak var userPhoneTextField: UITextField!;
  3. @IBOutlet weak var userPasswordTextField: UITextField!;
  4. @IBOutlet weak var userConfirmPasswordTextField: UITextField!;
  5. @IBOutlet weak var userPlugTextField: UITextField!;
  6.  
  7.  
  8. override func viewDidLoad() {
  9. super.viewDidLoad()
  10.  
  11. // Do any additional setup after loading the view.
  12. }
  13.  
  14. override func didReceiveMemoryWarning() {
  15. super.didReceiveMemoryWarning()
  16. // Dispose of any resources that can be recreated.
  17. }
  18.  
  19. @IBAction func RegisterButtonTapped(_ sender: Any) {
  20.  
  21. let userName = userNameTextField.text;
  22. let userPhone = userPhoneTextField.text;
  23. let userPassword = userPasswordTextField.text;
  24. let userConfirmPassword = userConfirmPasswordTextField.text;
  25. let userPlug = userPlugTextField.text;
  26.  
  27. // Check for empty fields
  28. if(userName!.isEmpty || userPhone!.isEmpty || userPassword!.isEmpty || userConfirmPassword!.isEmpty || userPlug!.isEmpty)
  29. {
  30.  
  31. // Display alert mmessage
  32.  
  33. displayMyAlertMessage(userMessage: "All fields are required")
  34.  
  35. return;
  36. }
  37.  
  38. // check if passwords match
  39. if(userPassword != userConfirmPassword)
  40.  
  41. {
  42. // Display an alert message
  43. displayMyAlertMessage(userMessage: "Passwords do not match")
  44. return;
  45. }
  46.  
  47. // Store data
  48.  
  49. UserDefaults.standard.set(userName, forKey: "userName")
  50. UserDefaults.standard.set(userName, forKey: "userPhone")
  51. UserDefaults.standard.set(userName, forKey: "userPassword")
  52. UserDefaults.standard.set(userName, forKey: "userPlug")
  53. UserDefaults.standard.synchronize();
  54.  
  55. // Display alert message with confirmation
  56. _ = UIAlertController(title:"Alert", message:"Registration is successful. Thank you!", preferredStyle: UIAlertControllerStyle.alert);
  57.  
  58. _ = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default){ action in
  59. self.dismiss(animated: true, completion:nil)
  60. }
  61.  
  62. myAlert.addAction(okAction);
  63. self.present(myAlert, animated:true, completion:nil)
  64.  
  65. }
  66. func displayMyAlertMessage(userMessage:String)
  67. {
  68.  
  69. let myAlert = UIAlertController(title:"Alert", message:userMessage, preferredStyle: UIAlertControllerStyle.alert);
  70.  
  71. let okAction = UIAlertAction(title:"Ok", style: UIAlertActionStyle.default, handler:nil);
  72.  
  73. myAlert.addAction(okAction);
  74.  
  75. self.present(myAlert, animated:true, completion:nil);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement