sort an array of dictionary entries by date key

As Matt suggests, make your model like this:

struct DateStruct {
   let date: Date
   let values: [Double]
}

var dateStructsArray: [DateStruct] = []
//Populate your array in whatever way makes sense

Then sorting it is as simple as using a single call to sorted()

Your code might look like this:

let sortedDateStructs = dateStructsArray.sorted { $0.date < $1.date }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top