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 { $ < $ }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top