Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "mix-questions" : [ {
- "1" : "Eu Ro Wang",
- "2" : "Keerti Soundappan",
- "3" : "Galadriel Coury",
- "4" : "Madelyn Koch",
- "answer" : "Madelyn Koch",
- "question" : "Which one is not a national officer?"
- }, {
- "question" : "test"
- } ],
- "users" : {
- "0vFQYnfIbahHdC1RsuNMW45HYNR2" : {
- "email" : "andyjiang55@yahoo.com",
- "username" : "itsandyjiang"
- },
- "Cs7sW01kSEYHYZmBISvjYc1QmDy1" : {
- "email" : "test@gmail.com",
- "games-played" : 0,
- "username" : "test"
- },
- "GypKikOJbfOPV4m43mQTnLMWBYG3" : {
- "email" : "andyjiang@yahoo.com",
- "games-played" : 0,
- "username" : "andyjiang"
- },
- "Khf6jRX7uuZs40x8w7zapziCsr73" : {
- "email" : "andyjiang57@yahoo.com",
- "games-played" : 0,
- "username" : "itsandyjiang3"
- },
- "OAa5bbNc65acxmr6mauyIQ6bqHb2" : {
- "email" : "andyjiang56@yahoo.com",
- "games-played" : 0,
- "username" : "itsandyjiang2"
- },
- "YxxBBxS2WkWtrY8PnLx4jfDqV3o2" : {
- "email" : "andyjiang1@yahoo.com",
- "games-played" : 0,
- "username" : "itsandyjiang5"
- },
- "taikB5Gp1kaAmuPpiHxPoiKmjf03" : {
- "email" : "andyjiang2@yahoo.com",
- "games-played" : 0,
- "username" : "itsandyjiang9"
- }
- }
- }
- func render() {
- let ref = Database.database().reference(fromURL: "https://testtest.firebaseio.com/")
- let userID = Auth.auth().currentUser?.uid
- ref.child("users").child(userID!).observeSingleEvent(of: .value, with: { (snapshot) in
- // Get user value
- let value = snapshot.value as? NSDictionary
- let username = value?["username"] as? String ?? ""
- let gamesPlayed = value?["games-played"] as? String ?? ""
- self.usernameLabel.text = username.
- self.gamesPlayedLabel.text = gamesPlayed //Setting of label from data
- // ...
- }) { (error) in
- print(error.localizedDescription)
- }
- }
- let ref = Database.database().reference(fromURL: "https://testtest.firebaseio.com/")
- let usersReference = ref.child("users").child(user.uid)
- let values = ["username": self.usernameTextField.text!, "email": self.emailTextField.text!, "games-played": 0] as [String : Any]
- usersReference.updateChildValues(values, withCompletionBlock: { (err, ref) in
- if err != nil {
- print(err!)
- return
- }
- //Successfully registered user's data to database
- self.errorLabel.alpha = 0
- self.present((self.storyboard?.instantiateViewController(withIdentifier: "TabBarViewController"))!, animated: false, completion: nil)
- })
Add Comment
Please, Sign In to add comment