Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //INSIDE OF OUR LOADLASTMESSAGES FUNCTION
- //...
- //We save when the earliest message was sent in order to get ones previous to it when we want to load more.
- self.earliestMessageTime = result!.data.start
- //Convert the [Any] package we get into a dictionary of String and Any
- let messageDict = result!.data.messages as! [[String:String]]
- //Creating new messages from it and putting them at the end of messages array
- for m in messageDict{
- let message = Message(message: m["message"]! , username: m["username"]!, uuid: m["uuid"] as! String)
- self.messages.append(message)
- }
- //Reload the table with the new messages and bring the tableview down to the bottom to the most recent messages
- self.tableView.reloadData()
- if(!self.messages.isEmpty){
- let indexPath = IndexPath(row: self.messages.count-1, section: 0)
- self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement