I am fetching some data from my Firebase Storage. The data arrives as a snapshot:
FirebaseDatabase.userMessagesReference?.child(contact.uid).queryOrderedByKey().queryEnding(atValue: lastMessage?.key ?? latestMessage?.key).queryLimited(toLast: 10).observeSingleEvent(of: .value, with: { (messageKeysSnapshot) in
while let childSnap = messageKeysSnapshot.children.nextObject() as? DataSnapshot {
print(childSnap)
}
}, withCancel: { (error) in
print(error.localizedDescription)
})
I'd like to get every child of the children array. Unfortunately, something seems to be wrong, it does not work as expected. Instead of returning every child within the while-loop, the first child is just returned infinite times (and there are at least 10 messages in the database).
Also, when checking the messageKeysSnapshot and printing it to the console (by setting a breakpoint, etc...), I can see that there are several children. I definitely think that there's something wrong with the children
enumerator.
How can I get every child once?