I have an array, workoutData, of string dates in the format EEEE, d MMM, yyyy so the dates are saved as Tuesday, 30 Apr, 2019, Thursday, 25 Apr, 2019 and Saturday, 27 Apr, 2019 etc. I have tried using the sorted(by:) method below however this orders the dates alphabetically.
let orderedArray = self.workoutData.sorted(by: { $0.compare($1) == .orderedDescending})
How can I order this array in a descending order by date? I would like to keep the individual dates as strings and I am using these to populate a tableView.
Excuse the lack of experience. Thanks
(NS)DateFormatterto interpret the Date String as Date and then sort.Dateonce when loading the data. Don't keep the strings around. This will make all future processing much more efficient. This includes sorting and later showing those dates to users in the proper format for their locale.