0

I have an array of NSDates in swift. The dates are only hours and minutes. I have tried

times.sortInPlace({ $0.date.compare($1.date) == NSComparisonResult.OrderedAscending })

but I get an error "Static member 'date' cannot be used on instance of type 'NSDate' and I get the same error with the 1970 attempt as well.

Leo Dabus
  • 229,809
  • 59
  • 489
  • 571
RubberDucky4444
  • 2,330
  • 5
  • 38
  • 70
  • 5
    You can look at this http://stackoverflow.com/questions/26577496/how-do-i-sort-a-swift-array-containing-instances-of-nsmanagedobject-subclass-by – Breek Feb 18 '16 at 19:49

1 Answers1

3

edit/update:

Swift 3 or later NSDate is now Date and it conforms to Comparable protocol. Mutating method sortInPlace has also been renamed to sort:

times.sort()

You are trying to access NSDate date property. Try like this:

times.sortInPlace({ $0.compare($1) == NSComparisonResult.OrderedAscending })
Leo Dabus
  • 229,809
  • 59
  • 489
  • 571