The following is my database design in firebase
- Sports
- MainCategory (hypothetical category name)
- SubCategory1
- K_tgbBt6Vx0-kkg7e63
- name:football
- K_tgbBt6Vx0-kkg7a99
- name:golf
- Subcategory2
- K_tgbBt6Vx0-kkgad21
- name:Snooker
- K_tgbBt6Vx0-kkg7e00
- name:Table Tennis
- MainCategory2
- SomeOtherSubCategory1
-K_tgbBt6Vx0-kkg7e00
My Aim: To get all the sports under the sports node and display them category wise(i.e MainCategory and Sub category) in a uicollectionview and allow the user to select sports of his choice.
Eg. display
Main Category1
SubCategory1
Football, Golf
SubCategory2
Table Tennis, Snooker
Main Category2
SomeOtherSubCategory1
Hockey,Tennis
The following approaches only take me one level deeper in the node
rootref.child("sports").observe(.value, with: { (snapshot) in
let mainCategory = snapshot.key
for child in snapshot.children{
print(child)
}})
rootref.child("sports").observe(.childAdded, with: { (snapshot) in
let mainCategory = snapshot.key
let mySnapshot = snapshot.value! as! NSDictionary
}) { (error) in
print(error.localizedDescription)
}
Also if there is any other way i could structure my database, kindly let me know


