What is the best way to randomly sort a list of objects after you have fetched all the data? I've only been able to fetch the data, but don't know how to randomly sort it.
Firebase structure:
questions --> id: 1
Function to fetch all objects:
func fetchQuestions(completion: @escaping ([UserModel])->()) {
let postRef = self.databaseRef.child("questions")
postRef.observeSingleEvent(of: .value, with: { (poster) in
var resultsArray = [UserModel]()
for post in poster.children {
let post = UserModel(snapshot: post as? DataSnapshot)
resultsArray.append(post)
}
completion(resultsArray)
}) { (error) in
print(error.localizedDescription)
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…