I have an array called myArray in which dictionaries are added I want that dictionary to be sorted by time which is a key in dictionary. And that time is in String. The date format of time is "yyyy/MM/dd HH:mm:ss"
I tried with below code solution but gives a warning of "Cast from 'String?' to unrelated type 'Date' always fails".
let sortedArray = self.myArray.sorted{ ($0["Time"] as? Date)! > ($1["Time"] as? Date)! }
print(sortedArray)
If anyone can help me out, Thank You.
DateFormatter(v as? T)!is quite funny ;-) Next time, you can simply dov as! Tbro. I highly recommend taking the time to fully learn Swift Optionals — gonna help you a lot long term!