Sort an array of dates in swift

1

I have this array:

let arrayFechas = [2016-11-21 23:00:00 +0000, 2016-11-28 23:00:00 +0000, 2016-11-22 23:00:00 +0000, 2016-11-23 23:00:00 +0000, 2016-11-18 23:00:00 +0000, 2016-11-25 23:00:00 +0000, 2016-11-19 23:00:00 +0000, 2016-11-26 23:00:00 +0000, 2016-11-20 23:00:00 +0000, 2016-11-27 23:00:00 +0000]

And what I want, is to be able to sort it by ascending date. I have this code, but I get an error:

arrayfechas.sort({ $0.date.compare($1.date) == ComparisonResult.orderAscending })

This is the error that gives me:

  

Argument passed to call that takes no arguments

I use swift 3

    
asked by 21.11.2016 в 09:11
source

1 answer

1

Whether it is an array of dates in text format or an array of NSDate , all you have to do is the following:

let orderedDates = arrayFechas.sorted()

What you have to know, that the array as you have passed it is neither of them (you would miss the quotes for each date)

I leave the documentation just in case (although with a simple click you can see it) link

    
answered by 21.11.2016 / 09:24
source