Trying to come up with some logic that could help in documenting few resources for firebase. Have looked up few resources in regards to the problem, this question somewhat resembles the issue but not to the extend to solve it. SimillarQuestion . And the avilable doc doesn't mention any logic to implement it either GoogleDoc.
How to get only the keys from a given firebase json tree? As they say a pic tells thousand words. Have got the below mentioned tree for firebase setup. And at mentioned is the required out put where it is displayed to the user in a table view.
--uniUsers
|
|Fruits
| |
| |Apple:true
| |Kiwi:true
| |Orange:true
|
|Veggies
|
|Carrot:true
|Onions:true
|Lettuce:true
Swift Code
func fetchTotalUsers(){
let tempUniId = "Fruits"
let refUniId = Database.database().reference(withPath: "UniUsers/\(tempUniId)")
refUniId.observe(.value, with: { (snapp) in
print("Value><", snapp.key)
print("Key><", snapp.value!)
}
}
Swift OutPut:
Value >< Fruits
Key >< {
Apple = 1;
Kiwi = 1;
Orange = 1;
}
Required Output
Apple
Kiwi
Orange