How to reverse order of items from Firebase

前端 未结 2 386
花落未央
花落未央 2021-01-16 15:56

How can I reverse the order of this list in from Firebase? I want the last item to be the first. I tried to use queryOrdered, but that did not make a difference

2条回答
  •  粉色の甜心
    2021-01-16 16:39

    As @Frank says, you need to sort your results client-side.

    You can either sort the array with something like this

    let sorted = self.RquestInfoArray.sorted(by: { (r1: RequestInfoType, r2: RequestInfoType) -> Bool in
                return r1.dateAmount > r2.dateAmount
    })
    

    but if you really just want to reverse the array, probably simpler just to add your new elements at the start instead of the end

    self.RquestInfoArray.insert(contentsOf: array, at: 0)
    

提交回复
热议问题