Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. //INSIDE OF OUR LOADLASTMESSAGES FUNCTION
  2. //...
  3.  
  4. //We save when the earliest message was sent in order to get ones previous to it when we want to load more.
  5. self.earliestMessageTime = result!.data.start
  6.  
  7. //Convert the [Any] package we get into a dictionary of String and Any
  8. let messageDict = result!.data.messages as! [[String:String]]
  9.  
  10. //Creating new messages from it and putting them at the end of messages array
  11. for m in messageDict{
  12. let message = Message(message: m["message"]! , username: m["username"]!, uuid: m["uuid"] as! String)
  13. self.messages.append(message)
  14. }
  15. //Reload the table with the new messages and bring the tableview down to the bottom to the most recent messages
  16. self.tableView.reloadData()
  17. if(!self.messages.isEmpty){
  18. let indexPath = IndexPath(row: self.messages.count-1, section: 0)
  19. self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement