I've already read similar questions/answer, but none of it resolve my problem.
I've an object like this
class Chat {
unreadMessages: Int = 0
messages: Int = 0
}
Then I have an array of Chat objects, and I need to order it by multiple criteria, first by chat with grater unread messages and then chat with grater total messages.
Es.
Obj TotMes Unread
Chat A 10 3
Chat B 1 0
Chat C 4 0
Chat D 9 9
Desidered output:
Chat D 9 9
Chat A 10 3
Chat C 4 0
Chat B 1 0
I try with this sort alhoritm, but don't seems work:
let sorted = chats.sort({ (c1, c2) -> Bool in
if c1.unreadMessages > c2.unreadMessages {
return true
}
if c1.messages > c2.messages {
return true
}
return false
})
Can someone explain me what is wrong with this?
c1.unreadMessages < c2.unreadMessages?