2016-02-18 31 views
0

我有一個swift NSDates的數組。日期只有幾小時和幾分鐘。我曾嘗試排序NSDates的數組swift

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

,但我得到一個錯誤「靜態成員‘日期’不能在類型‘的NSDate’的情況下使用,我得到了1970年的嘗試,以及同樣的錯誤。

+5

你可以看一下這個http://stackoverflow.com/questions/26577496/how-do-i-sort-a-swift-array-containing-實例-的-nsmanagedobject子類,由 – Breek

回答

3

你是試圖訪問的NSDate日期屬性嘗試這樣的:

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