Guest User

Untitled

a guest
Jan 13th, 2019
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. {
  2. "mix-questions" : [ {
  3. "1" : "Eu Ro Wang",
  4. "2" : "Keerti Soundappan",
  5. "3" : "Galadriel Coury",
  6. "4" : "Madelyn Koch",
  7. "answer" : "Madelyn Koch",
  8. "question" : "Which one is not a national officer?"
  9. }, {
  10. "question" : "test"
  11. } ],
  12. "users" : {
  13. "0vFQYnfIbahHdC1RsuNMW45HYNR2" : {
  14. "email" : "andyjiang55@yahoo.com",
  15. "username" : "itsandyjiang"
  16. },
  17. "Cs7sW01kSEYHYZmBISvjYc1QmDy1" : {
  18. "email" : "test@gmail.com",
  19. "games-played" : 0,
  20. "username" : "test"
  21. },
  22. "GypKikOJbfOPV4m43mQTnLMWBYG3" : {
  23. "email" : "andyjiang@yahoo.com",
  24. "games-played" : 0,
  25. "username" : "andyjiang"
  26. },
  27. "Khf6jRX7uuZs40x8w7zapziCsr73" : {
  28. "email" : "andyjiang57@yahoo.com",
  29. "games-played" : 0,
  30. "username" : "itsandyjiang3"
  31. },
  32. "OAa5bbNc65acxmr6mauyIQ6bqHb2" : {
  33. "email" : "andyjiang56@yahoo.com",
  34. "games-played" : 0,
  35. "username" : "itsandyjiang2"
  36. },
  37. "YxxBBxS2WkWtrY8PnLx4jfDqV3o2" : {
  38. "email" : "andyjiang1@yahoo.com",
  39. "games-played" : 0,
  40. "username" : "itsandyjiang5"
  41. },
  42. "taikB5Gp1kaAmuPpiHxPoiKmjf03" : {
  43. "email" : "andyjiang2@yahoo.com",
  44. "games-played" : 0,
  45. "username" : "itsandyjiang9"
  46. }
  47. }
  48. }
  49.  
  50. func render() {
  51. let ref = Database.database().reference(fromURL: "https://testtest.firebaseio.com/")
  52. let userID = Auth.auth().currentUser?.uid
  53. ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
  54. // Get user value
  55. let value = snapshot.value as? NSDictionary
  56. let username = value?["username"] as? String ?? ""
  57. let gamesPlayed = value?["games-played"] as? String ?? ""
  58. self.usernameLabel.text = username.
  59. self.gamesPlayedLabel.text = gamesPlayed //Setting of label from data
  60.  
  61. // ...
  62. }) { (error) in
  63. print(error.localizedDescription)
  64. }
  65. }
  66.  
  67. let ref = Database.database().reference(fromURL: "https://testtest.firebaseio.com/")
  68. let usersReference = ref.child("users").child(user.uid)
  69. let values = ["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "games-played": 0] as [String : Any]
  70. usersReference.updateChildValues(values, withCompletionBlock: { (err, ref) in
  71. if err != nil {
  72. print(err!)
  73. return
  74. }
  75.  
  76. //Successfully registered user's data to database
  77.  
  78. self.errorLabel.alpha = 0
  79. self.present((self.storyboard?.instantiateViewController(withIdentifier: "TabBarViewController"))!, animated: false, completion: nil)
  80.  
  81.  
  82. })
Add Comment
Please, Sign In to add comment