【问题标题】:Sort Array of NSDates swift [duplicate]快速排序NSDates数组[重复]
【发布时间】:2016-02-18 19:43:09
【问题描述】:

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

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

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

【问题讨论】:

标签: arrays swift sorting date nsdate


【解决方案1】:

编辑/更新:

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

times.sort()

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多