I am doing a chat messenger app, and i would like to show the last sent message on home menu as shown:
and my database looks like
in my view did load, i am putting a function of getAllMsg()
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Private Message"
// Do any additional setup after loading the view.
getAllMsg()
}
But in my getAllMsg()
function, I am unsure how should I access the last message for each recipient. I used this code:
func getAllMsg() {
self.users = []
let ref = Database.database().reference().child("privateMessages")
ref.queryLimited(toLast: 1).observeSingleEvent(of: .childAdded) { (snapshot) in
print(snapshot)
}
}
and I am getting the whole messages sent to my last recipient. Does anyone have any idea how should I go about this?