Having a hard time figuring out how to iterate through the my messages database so I can find a key that matches a user's phone number... this method crashes and all the other ways I've tried fail as well. I could really use the help thanks.
func retrieveMessages(){
let messagesDB = Database.database().reference().child("iMessenger/Messages")
messagesDB.observe(.childAdded, with: {(snapshot) in
let snapshotValue = snapshot.value as! Dictionary<String, String>
//This conditional is suppose to filter out messages that aren't to or from the user
if snapshotValue["sender"]! == userPhoneNumber || snapshotValue["receiver"]! == userPhoneNumber{
let text = snapshotValue["messageBody"]!
let sender = snapshotValue["sender"]!
let message = Message()
message.messageBody = text
message.sender = sender
self.messageArr.append(message)
self.configureTableView()
self.messagesTableView.reloadData()
self.scrollToLastRow()}}
)}