How I can shuffle my struct by variable priority
and display in TableView?
So now I have 20 documents in my struct, but later I will have 100+ documents in my struct.
5 or 7 or 10 documents will have priority
from 10 to 1, other documents have priority
0. Me need display 5 or 7 or 10 documents on top position in tableView. Other documents which have priority
0 must be located after firsts 5 or 7 or 10 documents in random order.
I. e. the firsts 5 or 7 or 10 documents should be placed depending on the priority, if a document has priority
10, it should be the first one, the next one which has priority
9 should be behind the document with priority
10 and so on to the document with priority 1. Other documents due be randomly in order.
This code which help me get documents from firestore
:
fileprivate func observeQuery() {
MBProgressHUD.showAdded(to: self.view, animated: true)
guard let query = query else { return }
let time = DispatchTime.now() + 0.5
listener = query.addSnapshotListener { [unowned self] (snapshot, error) in
if let snapshot = snapshot {
DispatchQueue.main.asyncAfter(deadline: time) {
var photoModels = snapshot.documents.map { (document) -> Photographer in
if let photoModel = Photographer(dictionary: document.data(), id: document.documentID) {
return photoModel
} else {
fatalError("Fatal error")
}
}
self.photographers = photoModels
// this need use shuffle
self.document = snapshot.documents
self.tableView.reloadData()
MBProgressHUD.hide(for: self.view, animated: true)
}
}
}
}