ios - 按日期参数过滤项目数组而不考虑时间

标签 ios swift filter nsdate

我有一个日期数组,我想根据用户选择的日期进行过滤。但是,由于每个对象也有时间,我很难正确过滤。

在我的 TableView 中,我想按日期参数过滤这个项目数组,而不比较时间。又名:

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.filter({$0.date == selectedDate}).count
        //count is always 0 because time is not exactly the same in any instance
    }

关于如何做到这一点有什么想法吗?

最佳答案

尝试使用系统日历的这个功能

Calendar.current.isDate($0.date, inSameDayAs: selectedDate)

如果您有其他需要澄清的问题,请查看此功能的苹果文档

https://developer.apple.com/documentation/foundation/calendar/2292885-isdate

关于ios - 按日期参数过滤项目数组而不考虑时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48216757/

相关文章:

ios - 如何在完成之前中断 UIView 动画?

ios - 我在将数据从 UITableView 传递到第二个 View 时遇到问题

ios - 将 Xib 与 ScrollView 一起使用 - Swift

python - CQL过滤方法-python

javascript - json jquery 过滤器 javascript 数组

ios - 将完成 block 添加到 enumerateObjectsWithOptions

ios - 在 Swift 函数之间传递索引值的最佳方式

ios - 如何设置透明导航栏? iOS 11 快速 4 Xcode 9

filter - 在哪里过滤状态?

ios - 使用 "Distributing Enterprise Apps for iOS Devices' 提供更新的应用程序?