I promise an EASY read :)
Howdy, I am currently stuck. I will like to query all post starting with the newest post first instead of the oldest post. Why? Because its the only way I can include pagination in my tableView. (which means reloading when user gets to the bottom)
Lets say I have 10 posts starting with the oldest #1 and the newest #10: 1,2,...,10 If I query limited to the first 5 post I get [1,2,3,4,5] then I reverse the array, which will show [5,4,3,2,1] on my tableview starting with 5.
ISSUE: The problem is once the user gets to the bottom of the tableview, if i query the next five posts starting with the timestamp of the last post, I get... [6,7,8,9,10]
But now my table view isn't correct anymore as it will show [5,4,3,2,1,10,9,8,7,6] I am hoping that if I can use the current device date as a timestamp and query the all post before as shown below: I can essentially get [10,9,8,7,6] then when user reaches the bottom: [10,9,8,7,6,5,4,3,2,1]
let todayTime: TimeInterval = NSDate().timeIntervalSince1970
FIRDatabase.database().reference().child("post").child(animal).queryOrderedByValue().queryEnding(atValue: todayTime, childKey: "datePost").queryLimited(toLast: 5).observe(.value, with: {(snapshot) in