Reputation: 597
I have messages
child that including
- "Some key"
- "messages"
- "child by autoid"
- "text": String
- "sender": String
- "child by autoid"
- "text": String
- "sender": String
- "create_date": Date
I need to retrieve messages as Array without auto id. Can I do that? I can't find the way to do it.
Now, I retrieve it to dictionary then map to array. but the problem is index changed while mapping. so how can I retrieve it to array?
Upvotes: 0
Views: 55
Reputation: 7546
You can observe the "messages"
child value, and then create an array of FIRDataSnapshot from the children.
let ref = FIRDatabase.database().reference().child("messages")
ref.observe(.value, with: snapshot in {
// each snap in snapshots
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
// do things
}
}
})
Upvotes: 1