对 NSDates 数组排序 swift

Sort Array of NSDates swift

我在 swift 中有一组 NSDates。日期只有小时和分钟。我试过了

times.sortInPlace({ [=11=].date.compare(.date) == NSComparisonResult.OrderedAscending })

但我收到错误消息“静态成员 'date' 不能用于 'NSDate' 类型的实例,我在 1970 年的尝试中也遇到了同样的错误。

edit/update:

Swift 3 或更高版本 NSDate 现在是 Date 并且它符合 Comparable 协议。变异方法 sortInPlace 也已重命名为 sort:

times.sort()

您正在尝试访问 NSDate 日期 属性。像这样尝试:

times.sortInPlace({ [=11=].compare() == NSComparisonResult.OrderedAscending })