I currently have a tuple array whose's first value is of type String and second value of type Double. The first value contains a date, and is in the format "MM/dd/yy".
I'm not using Date objects due to confliction in my code.
I'm having trouble sorting this array by String in descending order (recent to oldest) because of the MM.
For example, my array contains the following:
[("07/30/17", 5.0), ("08/30/17", 9.0), ("05/30/17", 5.0), ("05/28/17", 6.0)]
Calling tupleArray = tupleArray.sort( {$0.0 > $1.0} ) would produce the following:
[("08/30/17", 9.0), ("07/30/17", 5.0), ("05/30/17", 5.0), ("05/28/17", 6.0)]
That works as expected.
However, if I add a String entry "08/30/16", calling the same sort function produces the following:
[("08/30/17", 9.0), ("08/30/16", 30.0), ("07/30/17", 5.0), ("05/30/17", 5.0), ("05/28/17", 6.0)]
"08/30/16" is in the 2nd index when it should be the last index, because the year 16 is older then 17.
I've looked at:
What am I doing wrong?
Thanks!
Date(yes!) property and a computed property for the string representation. It makes life a lot easier.Datedoes not work well with my current implementation...is there a better solution to sort the dateStringsthen just switching toDateobjects?Dateobjects is the easier and better solution.