Reputation: 355
In firebase i'm trying to retrieve data stored in the firebase realtime database by using the childByAutoID() to give the data a unique identifier but the problem is i'm not entirely sure how to achieve this?
func retData(){
rootRef.child("users").child(userID).ChildByAutoID().observeEventType(.Value){
(snap: FIRDataSnapshot) in
self.simpleLabel.text = snap.value?.description
}
}
Json data structure
-userID
-childByAutoID
-player1
-email
Upvotes: 2
Views: 965
Reputation: 9955
If your JSON structure is:-
-users
-childByAutoID
-playerID
-email
Use :-
rootRef.child("users").observeEventType(.Value, withBlock: {(snap) in
if let userDict = snap.value as? [String:AnyObject]{
for each in userDict as [String: AnyObject] {
let autoID = each.0
//Here you retrieve your autoID
rootRef.child("users").child(autoID).child("player1").observeEventType(.Value, withBlock: {(playersDict) in
if let playerDictionary = playerDict.value as? [String:AnyObject]{
let emailID = playerDictionary["email"] as! String
//print(emailID)
}
})
}
}
})
Upvotes: 1