Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. 2016-06-16 02:04:37.586 ParseStarterProject-Swift[1959:117839] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ParseStarterProject_Swift.ViewController 0x7fcc9bc21f40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key switch.'
  2.  
  3. import UIKit
  4.  
  5. func displayAlert(title: String, message: String) {
  6.  
  7. let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
  8.  
  9. alert.addAction(UIAlertAction(title: "OK", style: .Default, handler: { (action) in
  10.  
  11. self.dismissViewControllerAnimated(true, completion: nil)
  12.  
  13. }))
  14.  
  15. self.presentViewController(alert, animated: true, completion: nil)
  16.  
  17. }
  18.  
  19. var activityIndicator: UIActivityIndicatorView = UIActivityIndicatorView()
  20.  
  21. @IBOutlet weak var username: UITextField!
  22.  
  23. @IBOutlet weak var password: UITextField!
  24.  
  25. @IBOutlet weak var selector: UISwitch!
  26.  
  27. @IBOutlet weak var mainButton: UIButton!
  28.  
  29. @IBOutlet weak var alternateButton: UIButton!
  30.  
  31. @IBAction func mainButton(sender: AnyObject) {
  32.  
  33. if username == "" || password == "" {
  34.  
  35. displayAlert("Error in form", message: "Please enter a username and a password")
  36.  
  37. } else {
  38.  
  39. activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
  40. activityIndicator.center = self.view.center
  41. activityIndicator.hidesWhenStopped = true
  42. activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray
  43. view.addSubview(activityIndicator)
  44. activityIndicator.startAnimating()
  45. UIApplication.sharedApplication().beginIgnoringInteractionEvents()
  46.  
  47. if selector.on == true {
  48.  
  49. // Rider Sign Up
  50.  
  51. let user = PFUser()
  52.  
  53. user.username = username.text
  54.  
  55. user.password = password.text
  56.  
  57. user["type"] = "rider"
  58.  
  59. user.signUpInBackgroundWithBlock({ (success, error) in
  60.  
  61. self.activityIndicator.stopAnimating()
  62. UIApplication.sharedApplication().endIgnoringInteractionEvents()
  63.  
  64. if success == true {
  65.  
  66. // Sign Up Successful
  67.  
  68. } else {
  69.  
  70. if let errorString = error!.userInfo["error"] as? String {
  71.  
  72. self.displayAlert("Failed SignUp", message: errorString)
  73.  
  74. }
  75.  
  76. }
  77.  
  78. })
  79.  
  80. } else {
  81.  
  82. // Driver Sign Up
  83.  
  84. let user = PFUser()
  85.  
  86. user.username = username.text
  87.  
  88. user.password = password.text
  89.  
  90. user["type"] = "driver"
  91.  
  92. user.signUpInBackgroundWithBlock({ (success, error) in
  93.  
  94. self.activityIndicator.stopAnimating()
  95. UIApplication.sharedApplication().endIgnoringInteractionEvents()
  96.  
  97. if success == true {
  98.  
  99. // Sign Up Successful
  100.  
  101. } else {
  102.  
  103. if let errorString = error!.userInfo["error"] as? String {
  104.  
  105. self.displayAlert("Failed SignUp", message: errorString)
  106.  
  107. }
  108.  
  109. }
  110.  
  111. })
  112.  
  113.  
  114. }
  115.  
  116. }
  117.  
  118. }
  119.  
  120. @IBAction func alternateButton(sender: AnyObject) {
  121. }
  122.  
  123. override func viewDidLoad() {
  124. super.viewDidLoad()
  125. }
  126.  
  127. override func didReceiveMemoryWarning() {
  128. super.didReceiveMemoryWarning()
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement