sort
swift4
ArrayOfDictionary

Sort Swift4 Array of Dictionary

class Message {
    var date: NSDate?
    var isSender: Bool
    var text: String?
    var friend: Friend?
}

 var messages: [Message]?
 ...


 messages = messages?.sorted(by: { (msg1, msg2) -> Bool in
        return msg1.date?.compare(msg2.date! as Date) == .orderedAscending
      })