I have an array, SetDataList, which is populated with the information below:
["2019-04-30 Set 1: 8 Reps 55kg", "2019-05-02 Set 1: 5 Reps 70kg", "2019-05-02 Set 2: 4 Reps 70kg", "2019-05-02 Set 3: 2 Reps 75kg"]
I am currently using the below code to order the array so that the sets, 1, 2 and 3 are grouped and appear as is in the array above.
SetDataList.sort(by: {$0 < $1})
However, I would also like to order the array in date descending order. I have previously performed this by using the following code although, this approach scrambles the set order.
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
let ordered = SetDataList.sorted { string1, string2 in
guard let date1 = dateFormatter.date(from: string1), let date2 = dateFormatter.date(from: string2) else { return false }
return date1 < date2
}
How can I implement multiple sorts? Thanks