I have three date objects. I want to know, which of them is the oldest. I found a lot about how to compare two dates, but not multiple...
So I have my three date variables:
var firstDate:Date!
var secondDate:Date!
var thridDate:Date!
and I assign dates to them:
firstDaten = dateOne
secondDate = dateTwo
thridDate = dateThree
How can I find out in Swift, which of my dates is the oldest?
Tanks for help!
[firstDate, secondDate, thridDate].sorted().prefix(1)minif you just want the earliest date. Only usesortedif you really need all of the dates sorted. Sorting the full array is more computationally expensive than just identifying the smallest value (though, admittedly, when dealing with so few records, it's not likely to result in observable performance difference). So, sort if you need to, but grabminif that's really all you care about.