I have a list of conversation which needs to be sorted on last updated time. I am able to do this but now i also need to add a check that if user is not included in conversation then it should appear at the end of list.
func sortConversationList () {
self.conversationList = self.conversationList.sorted(by: { $0.lastupdatedTime! > $1.lastupdatedTime! })
for (index, conversation) in self.conversationList.enumerated() {
if (conversation.isIncluded == kNo) {
self.conversationList.move(at: index, to: self.conversationList.endIndex-1)
}
}
self.tableView.reloadData()
}
mutating func move(at oldIndex: Int, to newIndex: Int) {
self.insert(self.remove(at: oldIndex), at: newIndex)
}
but this is not working properly. Any better way to do this in swift ?