ios - 按特定字段截断 firebase 项目

标签 ios swift firebase firebase-realtime-database

我是 iOS 和 Swift 的初学者,似乎无法截断数据库评论列表以仅显示当前活跃的评论。

评论有一个结束时间戳字段,它是一个整数,例如:1507522353

这是获取 10 条以上评论的代码区域:

commentsRef.observe(.childAdded, with: { (snapshot) -> Void in
  self.comments.append(snapshot)
  self.tableView.insertRows(at: [IndexPath(row: self.comments.count-1, section: self.kSectionComments)], with: UITableViewRowAnimation.automatic)
})

我只想附加(和显示)结束时间戳<当前时间戳的注释

谢谢

最佳答案

您可以使用 queryEnding(atValue:) 实现此目的,其中值是当前时间戳(以毫秒为单位)减一。查询按 endtimestamp 排序,以便指定结束于值查询的子键。

let now = Date().timeIntervalSince1970 * 1000.0
let query = commentsRef
    .queryOrdered(byChild: "endtimestamp")
    .queryEnding(atValue: now - 1)

query.observe(.childAdded, ...

关于ios - 按特定字段截断 firebase 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46630271/

相关文章:

firebase - 我必须从 Firebase 下载图像才能显示吗?

javascript - 由于巨大的回溯,Karma 输出不可读

ios - 如何存档文本颜色为渐变的 UItextfield?

iphone - 如何将 Core Data 集成到我现有的应用程序中?

ios - 自动布局 : How to create a simple UIView over keyboard using Swift

android - 多个sender id的情况下如何判断token是否需要刷新?

objective-c - 开发像 Facebook 新 iOS 应用程序中的侧滑菜单的最佳方法是什么?

ios - 从 Swift 3 中的 Dictionary<String, Any> 中获取值

swift - 按值对 Swift 字典数组进行排序

ios - webservice的输出没有使用alamofire快速提供所需的json